Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenTelemetry.Extensions] Add baggage Activity processor #1659

Merged
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
76226d5
feat: Add baggage span processor
MikeGoldsmith Apr 18, 2024
7a18c03
add changelog
MikeGoldsmith Apr 18, 2024
931e8a2
fix line endings, replace invalid icon
MikeGoldsmith Apr 18, 2024
11f4a3d
remove invalid icon from readme
MikeGoldsmith Apr 18, 2024
e2c8403
tweak readme line lengths
MikeGoldsmith Apr 18, 2024
64cd3bf
Merge branch 'main' into mike/baggage-span-processor
MikeGoldsmith Apr 18, 2024
9bfd757
move baggage processor to extensions project
MikeGoldsmith Apr 22, 2024
1be86f1
remove old project files
MikeGoldsmith Apr 22, 2024
8720ad4
revert sln changes
MikeGoldsmith Apr 22, 2024
b67ed25
update comonent owners
MikeGoldsmith Apr 22, 2024
1b0fdd6
update namespace
MikeGoldsmith Apr 22, 2024
51d1d0e
make class internal
MikeGoldsmith Apr 22, 2024
8b6c1e2
add tracer provider builder extension method
MikeGoldsmith Apr 22, 2024
1dfd06d
add example to readme
MikeGoldsmith Apr 22, 2024
4907fad
update api signature
MikeGoldsmith Apr 22, 2024
1727eca
Merge branch 'main' into mike/baggage-span-processor
MikeGoldsmith Apr 22, 2024
c3fb1c3
add changelog entry
MikeGoldsmith Apr 22, 2024
3ab5483
Merge branch 'mike/baggage-span-processor' of github.com:honeycombio/…
MikeGoldsmith Apr 22, 2024
f757947
fix file encoding
MikeGoldsmith Apr 22, 2024
efaea35
Merge branch 'main' into mike/baggage-span-processor
MikeGoldsmith Apr 23, 2024
8c5847d
rename to baggage activity processor
MikeGoldsmith Apr 24, 2024
e12824a
clean up after rename
MikeGoldsmith Apr 24, 2024
e4238c5
update example to show just the activity processor
MikeGoldsmith Apr 24, 2024
bc927a0
Apply suggestions from code review
MikeGoldsmith Apr 24, 2024
61edd97
update component owners for test project too
MikeGoldsmith Apr 24, 2024
ccf54ae
update readme to make trace context headers less specific
MikeGoldsmith Apr 24, 2024
8f9f235
Merge branch 'mike/baggage-span-processor' of github.com:honeycombio/…
MikeGoldsmith Apr 24, 2024
98eb76b
Update readme example text
MikeGoldsmith Apr 24, 2024
2a4852b
use guard to check for null builder
MikeGoldsmith Apr 24, 2024
85fd0e1
Merge branch 'main' into mike/baggage-span-processor
MikeGoldsmith Apr 25, 2024
15ca843
remove warning from readme
MikeGoldsmith Apr 25, 2024
8f5700c
tweak readme text
MikeGoldsmith Apr 25, 2024
6836c4f
Merge branch 'mike/baggage-span-processor' of github.com:honeycombio/…
MikeGoldsmith Apr 25, 2024
9e33de2
fix readme text
MikeGoldsmith Apr 25, 2024
d98d5a7
Merge branch 'main' into mike/baggage-span-processor
MikeGoldsmith Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ components:
- SergeyKanzhelev
src/OpenTelemetry.Extensions/:
- codeblanch
- mikegoldsmith
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved
src/OpenTelemetry.Extensions.AWS/:
- srprash
- atshaw43
Expand Down Expand Up @@ -114,6 +115,7 @@ components:
- SergeyKanzhelev
test/OpenTelemetry.Extensions.Tests/:
- codeblanch
- mikegoldsmith
test/OpenTelemetry.Extensions.AWS.Tests/:
- srprash
- atshaw43
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ OpenTelemetry.Logs.LogToActivityEventConversionOptions.StateConverter.set -> voi
OpenTelemetry.Trace.TracerProviderBuilderExtensions
static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AttachLogsToActivityEvent(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! loggerOptions, System.Action<OpenTelemetry.Logs.LogToActivityEventConversionOptions!>? configure = null) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAutoFlushActivityProcessor(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Func<System.Diagnostics.Activity!, bool>! predicate, int timeoutMilliseconds = 10000) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddBaggageActivityProcessor(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ OpenTelemetry.Logs.LogToActivityEventConversionOptions.StateConverter.set -> voi
OpenTelemetry.Trace.TracerProviderBuilderExtensions
static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AttachLogsToActivityEvent(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! loggerOptions, System.Action<OpenTelemetry.Logs.LogToActivityEventConversionOptions!>? configure = null) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAutoFlushActivityProcessor(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Func<System.Diagnostics.Activity!, bool>! predicate, int timeoutMilliseconds = 10000) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddBaggageActivityProcessor(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ OpenTelemetry.Logs.LogToActivityEventConversionOptions.StateConverter.set -> voi
OpenTelemetry.Trace.TracerProviderBuilderExtensions
static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AttachLogsToActivityEvent(this OpenTelemetry.Logs.OpenTelemetryLoggerOptions! loggerOptions, System.Action<OpenTelemetry.Logs.LogToActivityEventConversionOptions!>? configure = null) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAutoFlushActivityProcessor(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Func<System.Diagnostics.Activity!, bool>! predicate, int timeoutMilliseconds = 10000) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddBaggageActivityProcessor(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Extensions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Update OpenTelemetry SDK version to `1.8.1`.
([#1668](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1668))

* Add Baggage Activity Processor.
([#1659](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1659))

## 1.0.0-beta.4

Released 2023-Feb-27
Expand Down
22 changes: 22 additions & 0 deletions src/OpenTelemetry.Extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,25 @@ public static TracerProviderBuilder AddMyExporter(this TracerProviderBuilder bui
.AddAutoFlushActivityProcessor(a => a.Parent == null && (a.Kind == ActivityKind.Server || a.Kind == ActivityKind.Consumer), 5000);
}
```

### BaggageActivityProcessor

The BaggageActivityProcessor reads entries stored in Baggage from the parent context
and adds the baggage keys and values to the `Activity` as tags(attributes) on start.
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved

Add this activity processor to a tracer provider.

Warning!

Do not put sensitive information in Baggage.
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved

To repeat: a consequence of adding data to Baggage is that the keys and values
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think another important warning/note worth mentioning is that: This will likely result in duplicate information on multiple Activities. In the simplest case of an Activity for asp.net core request and one Activity for outgoing HttpClient call, the baggage information will be part of both these. It may be okay (or even desired), but depending on the backend/billing implications, it maybe not-so-desired.
A simple "Note:" here would be sufficient so users won't be surprised.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I understand. That's the intention of the baggage span processor; baggage entries are added to all subsequent Activities.

will appear in all outgoing trace context headers from the application.

Example of BaggageActivityProcessor:
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved

```cs
var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddBaggageActivityProcessor()
.Build();
```
21 changes: 21 additions & 0 deletions src/OpenTelemetry.Extensions/Trace/BaggageActivityProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;

namespace OpenTelemetry.Trace;

/// <summary>
/// Activity processor that adds <see cref="Baggage"/> fields to every new span.
/// </summary>
internal sealed class BaggageActivityProcessor : BaseProcessor<Activity>
{
/// <inheritdoc />
public override void OnStart(Activity activity)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MikeGoldsmith Should we check Activity.IsAllDataRequested before adding the tags?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed right? processors won't be called at all without that

{
foreach (var entry in Baggage.Current)
{
activity.SetTag(entry.Key, entry.Value);
}
}
}
22 changes: 22 additions & 0 deletions src/OpenTelemetry.Extensions/TracerProviderBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ public static TracerProviderBuilder AddAutoFlushActivityProcessor(

#pragma warning disable CA2000 // Dispose objects before losing scope
return builder.AddProcessor(new AutoFlushActivityProcessor(predicate, timeoutMilliseconds));
#pragma warning restore CA2000 // Dispose objects before losing scope
}

/// <summary>
/// Adds the <see cref="BaggageActivityProcessor"/> to the <see cref="TracerProviderBuilder"/>.
/// </summary>
/// <param name="builder"><see cref="TracerProviderBuilder"/> to add the <see cref="BaggageActivityProcessor"/> to.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddBaggageActivityProcessor(
this TracerProviderBuilder builder)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(builder);
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved
#else
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
#endif

#pragma warning disable CA2000 // Dispose objects before losing scope
return builder.AddProcessor(new BaggageActivityProcessor());
#pragma warning restore CA2000 // Dispose objects before losing scope
}
}
Loading