Skip to content

Commit

Permalink
Merge pull request Cysharp#215 from marekhanzlik/OpenTelemetry_upgrade
Browse files Browse the repository at this point in the history
OpenTelemetry upgrade to 0.2.0-alpha.40
  • Loading branch information
mayuki authored Nov 11, 2019
2 parents 414704b + 5114248 commit 18c8efd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/MagicOnion.OpenTelemetry/MagicOnion.OpenTelemetry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OpenTelemetry" Version="0.1.0-alpha-86593" />
<PackageReference Include="OpenTelemetry.Abstractions" Version="0.1.0-alpha-86593" />
<PackageReference Include="OpenTelemetry" Version="0.2.0-alpha.40" />
<PackageReference Include="OpenTelemetry.Abstractions" Version="0.2.0-alpha.40" />
</ItemGroup>

<ItemGroup>
Expand Down
80 changes: 43 additions & 37 deletions src/MagicOnion.OpenTelemetry/MagicOnionCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public OpenTelemetryCollectorLogger(IStatsRecorder statsRecorder, ITagger tagger
this.tagger = tagger;
// configure defaultTags included as default tag
this.defaultTags = defaultTags ?? TagContext.Empty;
if (defaultTags != TagContext.Empty)
if (this.defaultTags != TagContext.Empty)
{
foreach (var tag in defaultTags)
{
Expand Down Expand Up @@ -297,33 +297,36 @@ public override async ValueTask Invoke(ServiceContext context, Func<ServiceConte
// https://github.com/open-telemetry/opentelemetry-specification/blob/master/semantic-conventions.md#grpc

// span name must be `$package.$service/$method` but MagicOnion has no $package.
var spanBuilder = tracer.SpanBuilder(context.CallContext.Method, SpanKind.Server);
var spanBuilder = tracer.SpanBuilder(context.CallContext.Method).SetSpanKind(SpanKind.Server);

if (sampler != null)
{
spanBuilder.SetSampler(sampler);
}

using (spanBuilder.StartScopedSpan(out var span))
var span = spanBuilder.StartSpan();
try
{
try
{
span.SetAttribute("component", "grpc");
//span.SetAttribute("request.size", context.GetRawRequest().LongLength);
span.SetAttribute("component", "grpc");
//span.SetAttribute("request.size", context.GetRawRequest().LongLength);

await next(context);
await next(context);

//span.SetAttribute("response.size", context.GetRawResponse().LongLength);
span.SetAttribute("status_code", (long)context.CallContext.Status.StatusCode);
span.Status = OpenTelemetrygRpcStatusHelper.ConvertStatus(context.CallContext.Status.StatusCode).WithDescription(context.CallContext.Status.Detail);
}
catch (Exception ex)
{
span.SetAttribute("exception", ex.ToString());
//span.SetAttribute("response.size", context.GetRawResponse().LongLength);
span.SetAttribute("status_code", (long)context.CallContext.Status.StatusCode);
span.Status = OpenTelemetrygRpcStatusHelper.ConvertStatus(context.CallContext.Status.StatusCode).WithDescription(context.CallContext.Status.Detail);
}
catch (Exception ex)
{
span.SetAttribute("exception", ex.ToString());

span.SetAttribute("status_code", (long)context.CallContext.Status.StatusCode);
span.Status = OpenTelemetrygRpcStatusHelper.ConvertStatus(context.CallContext.Status.StatusCode).WithDescription(context.CallContext.Status.Detail);
throw;
}
span.SetAttribute("status_code", (long)context.CallContext.Status.StatusCode);
span.Status = OpenTelemetrygRpcStatusHelper.ConvertStatus(context.CallContext.Status.StatusCode).WithDescription(context.CallContext.Status.Detail);
throw;
}
finally
{
span.End();
}
}
}
Expand All @@ -347,33 +350,36 @@ public override async ValueTask Invoke(StreamingHubContext context, Func<Streami
// https://github.com/open-telemetry/opentelemetry-specification/blob/master/semantic-conventions.md#grpc

// span name must be `$package.$service/$method` but MagicOnion has no $package.
var spanBuilder = tracer.SpanBuilder(context.ServiceContext.CallContext.Method, SpanKind.Server);
var spanBuilder = tracer.SpanBuilder(context.ServiceContext.CallContext.Method).SetSpanKind(SpanKind.Server);

if (sampler != null)
{
spanBuilder.SetSampler(sampler);
}

using (spanBuilder.StartScopedSpan(out var span))
var span = spanBuilder.StartSpan();
try
{
try
{
span.SetAttribute("component", "grpc");
//span.SetAttribute("request.size", context.GetRawRequest().LongLength);
span.SetAttribute("component", "grpc");
//span.SetAttribute("request.size", context.GetRawRequest().LongLength);

await next(context);
await next(context);

//span.SetAttribute("response.size", context.GetRawResponse().LongLength);
span.SetAttribute("status_code", (long)context.ServiceContext.CallContext.Status.StatusCode);
span.Status = OpenTelemetrygRpcStatusHelper.ConvertStatus(context.ServiceContext.CallContext.Status.StatusCode).WithDescription(context.ServiceContext.CallContext.Status.Detail);
}
catch (Exception ex)
{
span.SetAttribute("exception", ex.ToString());
//span.SetAttribute("response.size", context.GetRawResponse().LongLength);
span.SetAttribute("status_code", (long)context.ServiceContext.CallContext.Status.StatusCode);
span.Status = OpenTelemetrygRpcStatusHelper.ConvertStatus(context.ServiceContext.CallContext.Status.StatusCode).WithDescription(context.ServiceContext.CallContext.Status.Detail);
}
catch (Exception ex)
{
span.SetAttribute("exception", ex.ToString());

span.SetAttribute("status_code", (long)context.ServiceContext.CallContext.Status.StatusCode);
span.Status = OpenTelemetrygRpcStatusHelper.ConvertStatus(context.ServiceContext.CallContext.Status.StatusCode).WithDescription(context.ServiceContext.CallContext.Status.Detail);
throw;
}
span.SetAttribute("status_code", (long)context.ServiceContext.CallContext.Status.StatusCode);
span.Status = OpenTelemetrygRpcStatusHelper.ConvertStatus(context.ServiceContext.CallContext.Status.StatusCode).WithDescription(context.ServiceContext.CallContext.Status.Detail);
throw;
}
finally
{
span.End();
}
}
}
Expand Down

0 comments on commit 18c8efd

Please sign in to comment.