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

[ASP.NET Core] Update enrich callbacks to use specific type. #3749

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
35fec21
[HttpClient] Export spans corresponding to retries
vishweshbankwar Oct 5, 2022
dbfdb56
nit
vishweshbankwar Oct 5, 2022
25332c5
Merge remote-tracking branch 'upstream/main' into vibankwa/enable-spa…
vishweshbankwar Oct 10, 2022
374e9ac
Update enrich callbacks
vishweshbankwar Oct 10, 2022
f36eaf5
update changelog
vishweshbankwar Oct 10, 2022
d8a1859
update desc
vishweshbankwar Oct 10, 2022
f28e435
clarify parameters
vishweshbankwar Oct 10, 2022
2010ad5
Merge branch 'main' into vibankwa/change-enrich-filter-aspnetcore
vishweshbankwar Oct 18, 2022
f5a26c4
resolve PR comments
vishweshbankwar Oct 18, 2022
596d9c1
Merge branch 'main' into vibankwa/change-enrich-filter-aspnetcore
vishweshbankwar Oct 18, 2022
77fca73
Merge branch 'main' into vibankwa/change-enrich-filter-aspnetcore
vishweshbankwar Oct 18, 2022
14d6417
add breaking comment
vishweshbankwar Oct 18, 2022
1c1eeaa
Merge branch 'vibankwa/change-enrich-filter-aspnetcore' of https://gi…
vishweshbankwar Oct 18, 2022
b8b13cb
update public api
vishweshbankwar Oct 18, 2022
7699da8
Merge branch 'main' into vibankwa/change-enrich-filter-aspnetcore
cijothomas Oct 19, 2022
06753ce
update readme
vishweshbankwar Oct 19, 2022
fdafb9c
fix comment
vishweshbankwar Oct 19, 2022
bc1fb65
Merge branch 'main' into vibankwa/change-enrich-filter-aspnetcore
vishweshbankwar Oct 19, 2022
a4c579d
update readme
vishweshbankwar Oct 19, 2022
92154d5
Merge branch 'vibankwa/change-enrich-filter-aspnetcore' of https://gi…
vishweshbankwar Oct 19, 2022
e4c3557
Merge branch 'main' into vibankwa/change-enrich-filter-aspnetcore
vishweshbankwar Oct 19, 2022
2813b77
Merge branch 'main' into vibankwa/change-enrich-filter-aspnetcore
cijothomas Oct 19, 2022
71e2eae
Update src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md
vishweshbankwar Oct 21, 2022
c1cbbad
Merge branch 'main' into vibankwa/change-enrich-filter-aspnetcore
vishweshbankwar Oct 21, 2022
bd814f1
Merge branch 'main' into vibankwa/change-enrich-filter-aspnetcore
cijothomas Oct 21, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.AspNetCoreInstrumentationOptions() -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnableGrpcAspNetCoreSupport.get -> bool
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnableGrpcAspNetCoreSupport.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Enrich.get -> System.Action<System.Diagnostics.Activity, string, object>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Enrich.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnException.get -> System.Action<System.Diagnostics.Activity, System.Exception>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnException.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStart.get -> System.Action<System.Diagnostics.Activity, Microsoft.AspNetCore.Http.HttpRequest>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStart.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStop.get -> System.Action<System.Diagnostics.Activity, Microsoft.AspNetCore.Http.HttpResponse>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStop.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.get -> System.Func<Microsoft.AspNetCore.Http.HttpContext, bool>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.RecordException.get -> bool
Expand All @@ -13,4 +17,4 @@ OpenTelemetry.Trace.TracerProviderBuilderExtensions
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action<OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions> configureAspNetCoreInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions> configureAspNetCoreInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions> configureAspNetCoreInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.AspNetCoreInstrumentationOptions() -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnableGrpcAspNetCoreSupport.get -> bool
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnableGrpcAspNetCoreSupport.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Enrich.get -> System.Action<System.Diagnostics.Activity, string, object>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Enrich.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnException.get -> System.Action<System.Diagnostics.Activity, System.Exception>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnException.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStart.get -> System.Action<System.Diagnostics.Activity, Microsoft.AspNetCore.Http.HttpRequest>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStart.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStop.get -> System.Action<System.Diagnostics.Activity, Microsoft.AspNetCore.Http.HttpResponse>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStop.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.get -> System.Func<Microsoft.AspNetCore.Http.HttpContext, bool>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.RecordException.get -> bool
Expand All @@ -13,4 +17,4 @@ OpenTelemetry.Trace.TracerProviderBuilderExtensions
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action<OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions> configureAspNetCoreInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions> configureAspNetCoreInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions> configureAspNetCoreInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,31 @@ public class AspNetCoreInstrumentationOptions
public Func<HttpContext, bool> Filter { get; set; }

/// <summary>
/// Gets or sets an action to enrich an Activity.
/// Gets or sets an action to enrich an Activity during start event.
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <remarks>
/// <para><see cref="Activity"/>: the activity being enriched.</para>
/// <para>string: the name of the event.</para>
/// <para>object: the raw object from which additional information can be extracted to enrich the activity.
/// The type of this object depends on the event, which is given by the above parameter.</para>
/// <para><see cref="HttpRequest"/>: the HttpRequest object from which additional information can be extracted to enrich the activity during start event.</para>
/// </remarks>
public Action<Activity, string, object> Enrich { get; set; }
public Action<Activity, HttpRequest> EnrichOnStart { get; set; }
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets or sets an action to enrich an Activity during stop event.
/// </summary>
/// <remarks>
/// <para><see cref="Activity"/>: the activity being enriched.</para>
/// <para><see cref="HttpResponse"/>: the HttpResponse object from which additional information can be extracted to enrich the activity during stop event.</para>
/// </remarks>
public Action<Activity, HttpResponse> EnrichOnStop { get; set; }

/// <summary>
/// Gets or sets an action to enrich an Activity during exception event.
/// </summary>
/// <remarks>
/// <para><see cref="Activity"/>: the activity being enriched.</para>
/// <para><see cref="Exception"/>: the Exception object from which additional information can be extracted to enrich the activity during exception event.</para>
/// </remarks>
public Action<Activity, Exception> EnrichOnException { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the exception will be recorded as ActivityEvent or not.
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* [Breaking] `Enrich` callback is split in to three different callbacks based on
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved
`OnStart`, `OnStop` and `OnException` event.
([#3749](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3749))

## 1.0.0-rc9.7

Released 2022-Sep-29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void OnStartActivity(Activity activity, object payload)

try
{
this.options.Enrich?.Invoke(activity, "OnStartActivity", request);
this.options.EnrichOnStart?.Invoke(activity, request);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -246,7 +246,7 @@ public void OnStopActivity(Activity activity, object payload)

try
{
this.options.Enrich?.Invoke(activity, "OnStopActivity", response);
this.options.EnrichOnStop?.Invoke(activity, response);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -345,7 +345,7 @@ public void OnException(Activity activity, object payload)

try
{
this.options.Enrich?.Invoke(activity, "OnException", exc);
this.options.EnrichOnException?.Invoke(activity, exc);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ void ConfigureTestServices(IServiceCollection services)
{
if (shouldEnrich)
{
options.Enrich = ActivityEnrichment;
options.EnrichOnStart = (activity, request) => { activity.SetTag("enrichedOnStart", "yes"); };
options.EnrichOnStop = (activity, response) => { activity.SetTag("enrichedOnStop", "yes"); };
}
})
.AddInMemoryExporter(exportedItems)
Expand All @@ -132,7 +133,8 @@ void ConfigureTestServices(IServiceCollection services)

if (shouldEnrich)
{
Assert.NotEmpty(activity.Tags.Where(tag => tag.Key == "enriched" && tag.Value == "yes"));
Assert.NotEmpty(activity.Tags.Where(tag => tag.Key == "enrichedOnStart" && tag.Value == "yes"));
Assert.NotEmpty(activity.Tags.Where(tag => tag.Key == "enrichedOnStop" && tag.Value == "yes"));
}

ValidateAspNetCoreActivity(activity, "/api/values");
Expand Down Expand Up @@ -519,7 +521,8 @@ void ConfigureTestServices(IServiceCollection services)
public async Task FilterAndEnrichAreOnlyCalledWhenSampled(SamplingDecision samplingDecision, bool shouldFilterBeCalled, bool shouldEnrichBeCalled)
{
bool filterCalled = false;
bool enrichCalled = false;
bool enrichOnStartCalled = false;
bool enrichOnStopCalled = false;
void ConfigureTestServices(IServiceCollection services)
{
this.tracerProvider = Sdk.CreateTracerProviderBuilder()
Expand All @@ -531,9 +534,13 @@ void ConfigureTestServices(IServiceCollection services)
filterCalled = true;
return true;
};
options.Enrich = (activity, methodName, request) =>
options.EnrichOnStart = (activity, request) =>
{
enrichCalled = true;
enrichOnStartCalled = true;
};
options.EnrichOnStop = (activity, request) =>
{
enrichOnStopCalled = true;
};
})
.Build();
Expand All @@ -550,7 +557,8 @@ void ConfigureTestServices(IServiceCollection services)

// Assert
Assert.Equal(shouldFilterBeCalled, filterCalled);
Assert.Equal(shouldEnrichBeCalled, enrichCalled);
Assert.Equal(shouldEnrichBeCalled, enrichOnStartCalled);
Assert.Equal(shouldEnrichBeCalled, enrichOnStopCalled);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,9 @@ public void GrpcPropagatesContextWithSuppressInstrumentationOptionSetToTrue()
.AddHttpClientInstrumentation()
.AddAspNetCoreInstrumentation(options =>
{
options.Enrich = (activity, eventName, obj) =>
options.EnrichOnStart = (activity, request) =>
{
switch (eventName)
{
case "OnStartActivity":
var request = (HttpRequest)obj;
activity.SetCustomProperty("customField", request.Headers["customField"].ToString());
break;
default:
break;
}
activity.SetCustomProperty("customField", request.Headers["customField"].ToString());
};
}) // Instrumenting the server side as well
.AddProcessor(processor.Object)
Expand Down