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

CustomProperty improvements #1261

Merged
merged 10 commits into from
Oct 6, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// </copyright>

using System;
using System.Diagnostics;
using System.Web;
using OpenTelemetry.Context.Propagation;

Expand All @@ -41,5 +42,16 @@ public class AspNetInstrumentationOptions
/// If Filter returns false or throw exception, the request is filtered out.
/// </summary>
public Func<HttpContext, bool> Filter { get; set; }

/// <summary>
/// Gets or sets an action to enrich an Activity.
eddynaka 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>
/// </remarks>
public Action<Activity, string, object> Enrich { get; set; }
}
}
9 changes: 7 additions & 2 deletions src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

* Instrumntation no longer store raw objects like `HttpRequest` in
Activity.CustomProperty. To enrich activity, use the Enrich action on the
instrumentation.
([#1261](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1261))

## 0.6.0-beta.1

Released 2020-Sep-15
Expand All @@ -10,8 +15,8 @@ Released 2020-Sep-15

Released 2020-08-28

* Added Filter public API on AspNetInstrumentationOptions to allow
filtering of instrumentation based on HttpContext.
* Added Filter public API on AspNetInstrumentationOptions to allow filtering of
instrumentation based on HttpContext.

* Asp.Net Instrumentation automatically populates HttpRequest, HttpResponse in
Activity custom property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,20 @@ public void RequestFilterException(string exception)
{
this.WriteEvent(3, exception);
}

[NonEvent]
public void EnrichmentException(Exception ex)
{
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
{
this.EnrichmentException(ex.ToInvariantString());
}
}

[Event(4, Message = "Enrichment threw exception. Exception {0}.", Level = EventLevel.Error)]
public void EnrichmentException(string exception)
{
this.WriteEvent(4, exception);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ public override void OnStartActivity(Activity activity, object payload)

if (activity.IsAllDataRequested)
{
activity.SetCustomProperty(RequestCustomPropertyName, request);
try
{
this.options.Enrich?.Invoke(activity, "OnStartActivity", request);
}
catch (Exception ex)
{
AspNetInstrumentationEventSource.Log.EnrichmentException(ex);
}

if (request.Url.Port == 80 || request.Url.Port == 443)
{
activity.SetTag(SemanticConventions.AttributeHttpHost, request.Url.Host);
Expand Down Expand Up @@ -159,7 +167,15 @@ public override void OnStopActivity(Activity activity, object payload)

var response = context.Response;

activityToEnrich.SetCustomProperty(ResponseCustomPropertyName, response);
try
{
this.options.Enrich?.Invoke(activity, "OnStopActivity", response);
}
catch (Exception ex)
{
AspNetInstrumentationEventSource.Log.EnrichmentException(ex);
}

activityToEnrich.SetTag(SemanticConventions.AttributeHttpStatusCode, response.StatusCode);

activityToEnrich.SetStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// </copyright>

using System;
using System.Diagnostics;
using Microsoft.AspNetCore.Http;
using OpenTelemetry.Context.Propagation;

Expand All @@ -41,5 +42,16 @@ public class AspNetCoreInstrumentationOptions
/// If Filter returns false or throw exception, the request is filtered out.
/// </summary>
public Func<HttpContext, bool> Filter { get; set; }

/// <summary>
/// Gets or sets an action to enrich an Activity.
/// </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>
/// </remarks>
public Action<Activity, string, object> Enrich { get; set; }
}
}
13 changes: 9 additions & 4 deletions src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

* Instrumntation no longer store raw objects like `HttpRequest` in
Activity.CustomProperty. To enrich activity, use the Enrich action on the
instrumentation.
([#1261](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1261))

## 0.6.0-beta.1

Released 2020-Sep-15
Expand All @@ -16,11 +21,11 @@ Released 2020-Sep-15

Released 2020-08-28

* Added Filter public API on AspNetCoreInstrumentationOptions to allow
filtering of instrumentation based on HttpContext.
* Added Filter public API on AspNetCoreInstrumentationOptions to allow filtering
of instrumentation based on HttpContext.

* Asp.Net Core Instrumentation automatically populates HttpRequest,
HttpResponse in Activity custom property
* Asp.Net Core Instrumentation automatically populates HttpRequest, HttpResponse
in Activity custom property

* Changed the default propagation to support W3C Baggage
([#1048](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1048))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,20 @@ public void RequestFilterException(string exception)
{
this.WriteEvent(3, exception);
}

[NonEvent]
public void EnrichmentException(Exception ex)
{
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
{
this.EnrichmentException(ex.ToInvariantString());
}
}

[Event(4, Message = "Enrichment threw exception. Exception {0}.", Level = EventLevel.Error)]
public void EnrichmentException(string exception)
{
this.WriteEvent(4, exception);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ public override void OnStartActivity(Activity activity, object payload)

if (activity.IsAllDataRequested)
{
activity.SetCustomProperty(RequestCustomPropertyName, request);
try
{
this.options.Enrich?.Invoke(activity, "OnStartActivity", request);
}
catch (Exception ex)
{
AspNetCoreInstrumentationEventSource.Log.EnrichmentException(ex);
}

var path = (request.PathBase.HasValue || request.Path.HasValue) ? (request.PathBase + request.Path).ToString() : "/";
activity.DisplayName = path;
Expand Down Expand Up @@ -152,7 +159,16 @@ public override void OnStopActivity(Activity activity, object payload)
}

var response = context.Response;
activity.SetCustomProperty(ResponseCustomPropertyName, response);

try
{
this.options.Enrich?.Invoke(activity, "OnStopActivity", response);
}
catch (Exception ex)
{
AspNetCoreInstrumentationEventSource.Log.EnrichmentException(ex);
}

activity.SetTag(SemanticConventions.AttributeHttpStatusCode, response.StatusCode);

if (TryGetGrpcMethod(activity, out var grpcMethod))
Expand Down
16 changes: 10 additions & 6 deletions src/OpenTelemetry.Instrumentation.GrpcNetClient/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

## Unreleased

* Instrumntation no longer store raw objects like `HttpRequestMessage` in
Activity.CustomProperty. To enrich activity, use the Enrich action on the
instrumentation.
([#1261](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1261))

## 0.6.0-beta.1

Released 2020-Sep-15

* The `grpc.method` and `grpc.status_code` attributes
added by the library are removed from the span. The information from these
attributes is contained in other attributes that follow the conventions of
OpenTelemetry.
* The `grpc.method` and `grpc.status_code` attributes added by the library are
removed from the span. The information from these attributes is contained in
other attributes that follow the conventions of OpenTelemetry.
([#1260](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1260)).

## 0.5.0-beta.2

Released 2020-08-28

* NuGet package renamed to OpenTelemetry.Instrumentation.GrpcNetClient to
more clearly indicate that this package is specifically for gRPC client
* NuGet package renamed to OpenTelemetry.Instrumentation.GrpcNetClient to more
clearly indicate that this package is specifically for gRPC client
instrumentation. The package was previously named
OpenTelemetry.Instrumentation.Grpc.
([#1136](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1136))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// limitations under the License.
// </copyright>

using System;
using System.Diagnostics;

namespace OpenTelemetry.Instrumentation.GrpcNetClient
{
/// <summary>
Expand All @@ -25,5 +28,16 @@ public class GrpcClientInstrumentationOptions
/// Gets or sets a value indicating whether down stream instrumentation is suppressed (disabled).
/// </summary>
public bool SuppressDownstreamInstrumentation { get; set; }

/// <summary>
/// Gets or sets an action to enrich an Activity.
/// </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>
/// </remarks>
public Action<Activity, string, object> Enrich { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ public override void OnStartActivity(Activity activity, object payload)

if (activity.IsAllDataRequested)
{
activity.SetCustomProperty(RequestCustomPropertyName, request);
try
{
this.options.Enrich?.Invoke(activity, "OnStartActivity", request);
}
catch (Exception ex)
{
GrpcInstrumentationEventSource.Log.EnrichmentException(ex);
}

activity.SetTag(SemanticConventions.AttributeRpcSystem, GrpcTagHelper.RpcSystemGrpc);

if (GrpcTagHelper.TryParseRpcServiceAndRpcMethod(grpcMethod, out var rpcService, out var rpcMethod))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
// limitations under the License.
// </copyright>

using System;
using System.Diagnostics.Tracing;
using OpenTelemetry.Internal;

namespace OpenTelemetry.Instrumentation.GrpcNetClient.Implementation
{
Expand All @@ -31,5 +33,20 @@ public void NullPayload(string handlerName, string eventName)
{
this.WriteEvent(1, handlerName, eventName);
}

[NonEvent]
public void EnrichmentException(Exception ex)
{
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
{
this.EnrichmentException(ex.ToInvariantString());
}
}

[Event(2, Message = "Enrichment thrw exception. Exception {0}.", Level = EventLevel.Error)]
public void EnrichmentException(string exception)
{
this.WriteEvent(2, exception);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Internal\ExceptionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Trace\SemanticConventions.cs" />
</ItemGroup>

Expand Down
5 changes: 5 additions & 0 deletions src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

* Instrumntation no longer store raw objects like `HttpRequestMessage` in
Activity.CustomProperty. To enrich activity, use the Enrich action on the
instrumentation.
([#1261](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1261))

## 0.6.0-beta.1

Released 2020-Sep-15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// </copyright>

using System;
using System.Diagnostics;
using System.Net.Http;
using System.Runtime.CompilerServices;
using OpenTelemetry.Context.Propagation;
Expand Down Expand Up @@ -50,6 +51,17 @@ public class HttpClientInstrumentationOptions
/// </summary>
public Func<HttpRequestMessage, bool> Filter { get; set; }

/// <summary>
/// Gets or sets an action to enrich an Activity.
/// </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>
/// </remarks>
public Action<Activity, string, object> Enrich { get; set; }

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal bool EventFilter(string activityName, object arg1)
{
Expand Down
Loading