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

feat: publish OpenTelemetry support to NuGet listed latest version. #422

Merged
merged 22 commits into from
Jun 15, 2021

Conversation

guitarrapc
Copy link
Contributor

@guitarrapc guitarrapc commented Apr 6, 2021

closed #421

TL;DR;

  • CI: Enable CI and Release for Experimental package.
  • BreakingChange: Drop Metrics support as OpenTelemetry-dotnet 1.0.1 and higher does. (will be re-support in .NET 6,)
  • BreakingChange: Split IMagicOnionServerBuilder.AddOpenTelemetry() to Listener IMagicOnionServerBuilder.AddOpenTelemetry() and Instrumentation TracerProviderBuilder.AddMagicOnionInstrumentation(). This offer Standard OpenTelemetry usage and simpler MagicOnion Integration. (see sample code)
  • Enahance: Support OpenTelemetry Tracer Span Context Propagation for Server to Server scenario.
  • Package: Update MagicOnion.OpenTelemetry package suffix to beta2-1.1.0 which represent OpenTelemery 1.1.0-beta2.
    Nov/2021)
  • Package: Drop OpenTelemetry.Extensions.Hosting reference, No need wait package update anymore.

Summary

BreakingChange: Drop Metrics support

OpenTelemetry 1.0.1 is released for Tracer packages, however Metrics are dropped until .NET 6 release.
Follow to OpenTelemetry package, MagicOnion drop Metrics support.

BreakingChange: Split Listener and Instrumentations

Previously MagicOnion.OpenTelemetry integrate "Listen Activity" and "Enable Instrumentation" in single IMagicOnionServerBuilder.AddOpenTelemetry(). However this prevent user from standard OpenTelemetry usage.
Now it's separate to activity listener and enable instrumentation.

  • IMagicOnionServerBuilder.AddOpenTelemetry() listen Activity and DI MagicOnionTelemetryOptions.
  • TracerProviderBuilder.AddMagicOnionInstrumentation() enable MagicOnion Instrumentations.

before

 services.AddMagicOnion(options =>
      {
          options.GlobalFilters.Add(new MagicOnionOpenTelemetryTracerFilterFactoryAttribute());
          options.GlobalStreamingHubFilters.Add(new MagicOnionOpenTelemetryStreamingTracerFilterFactoryAttribute());

          // Exception Filter is inside telemetry
          options.GlobalFilters.Add(new ExceptionFilterFactoryAttribute());
      })
      .AddOpenTelemetry((options, provider, tracerBuilder) =>
      {
          tracerBuilder
              .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyService"))
              .AddAspNetCoreInstrumentation()
              .AddJaegerExporter();
          services.Configure<OpenTelemetry.Exporter.JaegerExporterOptions>(Configuration.GetSection("Jaeger"));
      });

after

// Register MagicOnion Filter for OpenTelemetry && Listen OpenTelemetry Activity
services.AddMagicOnion(options =>
    {
        options.GlobalFilters.Add(new MagicOnionOpenTelemetryTracerFilterFactoryAttribute());
        options.GlobalStreamingHubFilters.Add(new MagicOnionOpenTelemetryStreamingTracerFilterFactoryAttribute());

        options.GlobalFilters.Add(new ExceptionFilterFactoryAttribute());
    })
    .AddOpenTelemetry(); // Listen Activity

// choice1. Enable MagicOnion instrumentation via IServiceCollection.AddOpenTelemetryTracing integration.
services.AddOpenTelemetryTracing(configure => 
{ 
    configure
        .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyService"))
        .AddAspNetCoreInstrumentation()
        .AddMagicOnionInstrumentation() // enable MagicOnion instrumentation
        .AddJaegerExporter();
    services.Configure<OpenTelemetry.Exporter.JaegerExporterOptions>(Configuration.GetSection("Jaeger"));
});

// choice2. Enable MagicOnion instrumentation via TracerProviderBuilder Sdk
var jo = new OpenTelemetry.Exporter.JaegerExporterOptions();
configuration.GetSection("Jaeger").Bind(jo);
Sdk.CreateTracerProviderBuilder()
    .AddAspNetCoreInstrumentation()
    .AddMagicOnionInstrumentation() // enable MagicOnion instrumentation
    .AddJaegerExporter(o =>
    {
        o.AgentHost = jo.AgentHost;
        o.AgentPort = jo.AgentPort;
    })
    .Build();

Enahance: Support OpenTelemetry Context Propagation

Now OpenTelemetry Context will propagate from server to server. This is done via gRPC Request Header.
This enable external MagicOnion Service Span integrate to single TraceId and under caller Spanid.
Example shows external MagicOnion MicroServer is called from ChatApp.Server's ChatApp.Server.S2S operation.

image

// Caller ChatApp.Server Propagate Context to callee.
public class ChatService : ServiceBase<IChatService>, IChatService
{
    public async UnaryResult<Nil> SendReportAsync(string message)
    {
        logger.LogDebug($"{message}");

        // dummy external operation.

        // Server to Server operation
        var channel = GrpcChannel.ForAddress(Environment.GetEnvironmentVariable("Server2ServerEndpoint", EnvironmentVariableTarget.Process) ??  "http://localhost:4999");
        var client = MagicOnionClient.Create<IMessageService>(channel, new[]
        {
            // propagate trace context from ChatApp.Server to MicroServer
            new MagicOnionOpenTelemetryClientFilter(s2sActivity, options),
        });
        await client.SendAsync("hello");

        // dummy external operation.
    }
}

// callee MicroServer automatically obtain propagated OpenTelemetry Span Context through Request Header.
public class MessageService : ServiceBase<IMessageService>, IMessageService
{
    public async UnaryResult<string> SendAsync(string message)
    {
        await Task.Delay(TimeSpan.FromMilliseconds(20));
        return $"echo {message}";
    }
}

REF

Remove metrics from 1.0.0 release by cijothomas · Pull Request #1743 · open-telemetry/opentelemetry-dotnet
Metric support plans · Issue #1501 · open-telemetry/opentelemetry-dotnet

@guitarrapc guitarrapc self-assigned this Apr 6, 2021
@guitarrapc guitarrapc changed the title feat: publish OpenTelemetry support to NuGet 1.0.0-rc3 feat: publish OpenTelemetry support to NuGet 1.0.0-rc1.1 Apr 6, 2021
@guitarrapc guitarrapc marked this pull request as draft April 7, 2021 02:59
@guitarrapc guitarrapc force-pushed the feat/opentelemetry_100rc11 branch 2 times, most recently from 55c3218 to 5b4168b Compare June 1, 2021 01:47
@guitarrapc guitarrapc force-pushed the feat/opentelemetry_100rc11 branch from 5b4168b to 156adfe Compare June 1, 2021 01:55
@guitarrapc guitarrapc force-pushed the feat/opentelemetry_100rc11 branch from 4a1f6e2 to 5fee3fd Compare June 2, 2021 17:11
@guitarrapc guitarrapc marked this pull request as ready for review June 2, 2021 19:56
@guitarrapc guitarrapc changed the title feat: publish OpenTelemetry support to NuGet 1.0.0-rc1.1 feat: publish OpenTelemetry support to NuGet listed latest version. Jun 2, 2021
@guitarrapc
Copy link
Contributor Author

Linux has Tracer not sending issue.

open-telemetry/opentelemetry-dotnet#2050

@guitarrapc
Copy link
Contributor Author

guitarrapc commented Jun 2, 2021

* downgrade OpenTElemetry 1.1.0-beta2 can send trace on linux, but exporters install with Sdk.CreateTracerProviderBuilder() like mysql and others will not.

Known issue

Windows work as expected.

  • Linux could not identify ServiceName on Zipkin.
  • Linux can not co-work with Sdk.CreateTracerProviderBuilder() and IServiceCollection.AddOpenTelemetryTracing(). Only AddOpenTelemetryTracing() work.
    • work around, if you can accept same service name, IServiceCollection.AddOpenTelemetryTracing().AddSource(mysql, redis and other) instread of Sdk.CreateTracerProviderBuilder().

@guitarrapc
Copy link
Contributor Author

guitarrapc commented Jun 7, 2021

All know issues are solved by Splitting Instrumentation.
Ready for review.

@guitarrapc guitarrapc requested review from mayuki and neuecc June 7, 2021 11:04
@mayuki mayuki merged commit 8109c1d into master Jun 15, 2021
@mayuki mayuki deleted the feat/opentelemetry_100rc11 branch June 15, 2021 03:11
AntonC9018 pushed a commit to AntonC9018/MagicOnion that referenced this pull request Sep 13, 2022
feat: publish OpenTelemetry support to NuGet listed latest version.
AntonC9018 pushed a commit to AntonC9018/MagicOnion that referenced this pull request Sep 13, 2022
feat: publish OpenTelemetry support to NuGet listed latest version.
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.

MagicOnion.OpenTelemetry nuget package is outdated
2 participants