Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
35fec21
[HttpClient] Export spans corresponding to retries
Oct 5, 2022
dbfdb56
nit
Oct 5, 2022
25332c5
Merge remote-tracking branch 'upstream/main' into vibankwa/enable-spa…
Oct 10, 2022
374e9ac
Update enrich callbacks
Oct 10, 2022
f36eaf5
update changelog
Oct 10, 2022
d8a1859
update desc
Oct 10, 2022
f28e435
clarify parameters
Oct 10, 2022
2010ad5
Merge branch 'main' into vibankwa/change-enrich-filter-aspnetcore
Oct 18, 2022
f5a26c4
resolve PR comments
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
Oct 18, 2022
14d6417
add breaking comment
Oct 18, 2022
1c1eeaa
Merge branch 'vibankwa/change-enrich-filter-aspnetcore' of https://gi…
Oct 18, 2022
b8b13cb
update public api
Oct 18, 2022
7699da8
Merge branch 'main' into vibankwa/change-enrich-filter-aspnetcore
cijothomas Oct 19, 2022
06753ce
update readme
Oct 19, 2022
fdafb9c
fix comment
Oct 19, 2022
bc1fb65
Merge branch 'main' into vibankwa/change-enrich-filter-aspnetcore
vishweshbankwar Oct 19, 2022
a4c579d
update readme
Oct 19, 2022
92154d5
Merge branch 'vibankwa/change-enrich-filter-aspnetcore' of https://gi…
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.EnrichWithException.get -> System.Action<System.Diagnostics.Activity, System.Exception>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithException.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpRequest.get -> System.Action<System.Diagnostics.Activity, Microsoft.AspNetCore.Http.HttpRequest>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpRequest.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpResponse.get -> System.Action<System.Diagnostics.Activity, Microsoft.AspNetCore.Http.HttpResponse>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpResponse.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.EnrichWithException.get -> System.Action<System.Diagnostics.Activity, System.Exception>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithException.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpRequest.get -> System.Action<System.Diagnostics.Activity, Microsoft.AspNetCore.Http.HttpRequest>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpRequest.set -> void
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpResponse.get -> System.Action<System.Diagnostics.Activity, Microsoft.AspNetCore.Http.HttpResponse>
OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpResponse.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.
/// </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 request start event.</para>
/// </remarks>
public Action<Activity, string, object> Enrich { get; set; }
public Action<Activity, HttpRequest> EnrichWithHttpRequest { get; set; }

/// <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 request stop event.</para>
/// </remarks>
public Action<Activity, HttpResponse> EnrichWithHttpResponse { 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 on exception during request.</para>
/// </remarks>
public Action<Activity, Exception> EnrichWithException { get; set; }

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

## Unreleased

* `Enrich` callback is now split into 3 different callbacks based on the object
that is passed in to enrich activity. The new callbacks are
`EnrichWithHttpRequest`, `EnrichWithHttpResponse` and `EnrichWithException`.
([#3749](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3749))

## 1.0.0-rc9.8

Released 2022-Oct-17
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.EnrichWithHttpRequest?.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.EnrichWithHttpResponse?.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.EnrichWithException?.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.EnrichWithHttpRequest = (activity, request) => { activity.SetTag("enrichedOnStart", "yes"); };
options.EnrichWithHttpResponse = (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 enrichWithHttpRequestCalled = false;
bool enrichWithHttpResponseCalled = 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.EnrichWithHttpRequest = (activity, request) =>
{
enrichCalled = true;
enrichWithHttpRequestCalled = true;
};
options.EnrichWithHttpResponse = (activity, request) =>
{
enrichWithHttpResponseCalled = true;
};
})
.Build();
Expand All @@ -550,7 +557,8 @@ void ConfigureTestServices(IServiceCollection services)

// Assert
Assert.Equal(shouldFilterBeCalled, filterCalled);
Assert.Equal(shouldEnrichBeCalled, enrichCalled);
Assert.Equal(shouldEnrichBeCalled, enrichWithHttpRequestCalled);
Assert.Equal(shouldEnrichBeCalled, enrichWithHttpResponseCalled);
}

[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.EnrichWithHttpRequest = (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