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

[WIP] OWIN Instrumentation for OpenTelemetry #1472

Conversation

denisivan0v
Copy link

@denisivan0v denisivan0v commented Nov 5, 2020

Fixes #.

Changes

Please provide a brief description of the changes here.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Design discussion issue #
  • Changes in public API reviewed

@denisivan0v denisivan0v requested a review from a team November 5, 2020 17:01
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 5, 2020

CLA Check
The committers are authorized under a signed CLA.

}

[MethodImpl(MethodImplOptions.NoInlining)]
private Activity StartActivity(IOwinContext owinContext, out bool hasDiagnosticListener)
Copy link
Member

Choose a reason for hiding this comment

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

The recommendation is to use ActivitySource based instrumentation for any new instrumentations. DiagnosticListener based ones are "legacy".
This instructions are being documented here (WIP):
#1467

I can help with replacing the DS -> ActivitySource ones.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks @cijothomas, I'll replace DiagnosticListener with ActivitySource.

var activity = new Activity(ActivityName);

// Based on https://github.com/microsoft/ApplicationInsights-dotnet/blob/2.15.0/WEB/Src/Web/Web/Implementation/RequestTrackingExtensions.cs#L41
if (!activity.Extract(owinContext.Request.Headers))
Copy link
Member

Choose a reason for hiding this comment

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

We need to move on to Propagagators.DefaultTextMapPropagator approach.

Copy link
Author

Choose a reason for hiding this comment

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

Can you please point me to some examples?

Copy link
Member

Choose a reason for hiding this comment

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


if (traceParents != null && traceParents.Count > 0 && !string.IsNullOrEmpty(traceParents[0]))
{
// there may be several Request-Id or traceparent headers, but we only read the first one
Copy link
Member

Choose a reason for hiding this comment

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

This would go against the W3C TraceContext spec.
Here goes the compliance test FYI https://github.com/w3c/trace-context/blob/1ea757e565f3f68f453ebd62a010e6ae9d9be5f2/test/test.py#L134.

Copy link
Member

Choose a reason for hiding this comment

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

Once Propagator API is used, this would get handled by the TraceContextPropagator, and libraries don't have to write this code.

internal static class HeaderNames
{
public static readonly string CorrelationContext = "Correlation-Context";
public static readonly string RequestId = "Request-Id";
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this?

// // Microsoft.Net.Http.Headers headers (from https://github.com/dotnet/aspnetcore/blob/v5.0.0-rc.2.20475.17/src/Http/Headers/src/HeaderNames.cs)
internal static class HeaderNames
{
public static readonly string CorrelationContext = "Correlation-Context";
Copy link
Member

Choose a reason for hiding this comment

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

The W3C Baggage standard has decided to call it "Baggage".

internal const string BaggageHeaderName = "Baggage";

/// <summary>
/// Instruments incoming request with System.Diagnostics.Activity and notifies listeners with DiagnosticsSource.
/// </summary>
public sealed class DiagnosticsMiddleware : OwinMiddleware
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be public?


namespace OpenTelemetry.Instrumentation.Owin.Implementation
{
internal class HttpInListener : ListenerHandler
Copy link
Member

Choose a reason for hiding this comment

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

@denisivan0v, your middleware approach is pretty neat! My gut says you won't need this OpenTelemetry.Instrumentation.Owin project once you convert your instrumentation to use ActivitySource as suggested earlier. That is, by starting/stopping an Activity from your middleware using an ActivitySource allows the OpenTelemetry SDK to directly listen to the ActivitySource.

/// <summary>Adds a component to the OWIN pipeline for instrumenting incoming request with System.Diagnostics.Activity and notifying listeners with DiagnosticsSource.</summary>
/// <param name="appBuilder">The application builder.</param>
/// <returns>The application builder instance.</returns>
public static IAppBuilder UseOpenTelemetry(this IAppBuilder appBuilder)
Copy link
Member

Choose a reason for hiding this comment

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

Might want to document that this middleware should be applied as early as possible so as to time the entire middleware chain.

@cijothomas
Copy link
Member

Closing old PRs. Please re-open when resuming work on this. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants