public void BeginInvokeHubMethod(StreamingHubContext context, ArraySegment <byte> request, Type type) { foreach (var x in inner) { x.BeginInvokeHubMethod(context, request, type); } }
public void EndInvokeHubMethod(StreamingHubContext context, int responseSize, Type type, double elapsed, bool isErrorOrInterrupted) { foreach (var x in inner) { x.EndInvokeHubMethod(context, responseSize, type, elapsed, isErrorOrInterrupted); } }
public override async ValueTask Invoke(StreamingHubContext context, Func <StreamingHubContext, ValueTask> next) { // 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); if (sampler != null) { spanBuilder.SetSampler(sampler); } using (spanBuilder.StartScopedSpan(out var span)) { try { span.SetAttribute("component", "grpc"); //span.SetAttribute("request.size", context.GetRawRequest().LongLength); 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("status_code", (long)context.ServiceContext.CallContext.Status.StatusCode); span.Status = OpenTelemetrygRpcStatusHelper.ConvertStatus(context.ServiceContext.CallContext.Status.StatusCode).WithDescription(context.ServiceContext.CallContext.Status.Detail); throw; } } }
public void BeginInvokeHubMethod(StreamingHubContext context, ReadOnlyMemory <byte> request, Type type) { foreach (var x in inner) { x.BeginInvokeHubMethod(context, request, type); } }
public override async ValueTask Invoke(StreamingHubContext context, Func <StreamingHubContext, ValueTask> next) { _logger.LogInformation($"MyStreamingHubFilter Begin: {context.Path}"); await next(context); _logger.LogInformation($"MyStreamingHubFilter End: {context.Path}"); }
public void BeginInvokeHubMethod(StreamingHubContext context, ReadOnlyMemory <byte> request, Type type) { var spanContext = default(SpanContext); var label = CreateLabel(context); streamingHubRequestCounter.Add(spanContext, 1, label); streamingHubRequestSizeMeasure.Record(spanContext, request.Length, label); }
IEnumerable <KeyValuePair <string, string> > CreateLabel(StreamingHubContext context) { // StreamingHub start from {HubInterface}/{Method} var value = "/" + context.Path; var label = labelCache.GetOrAdd(value, new HashSet <KeyValuePair <string, string> >(defaultLabels) { new KeyValuePair <string, string>(MethodKey, value), }); return(label); }
public void EndInvokeHubMethod(StreamingHubContext context, int responseSize, Type type, double elapsed, bool isErrorOrInterrupted) { var spanContext = default(SpanContext); var label = CreateLabel(context); streamingHubElapsedMeasure.Record(spanContext, elapsed, label); streamingHubResponseSizeMeasure.Record(spanContext, responseSize, label); if (isErrorOrInterrupted) { streamingHubErrorCounter.Add(spanContext, 1, label); } }
public void EndInvokeHubMethod(StreamingHubContext context, int responseSize, Type type, double elapsed, bool isErrorOrInterrupted) { var map = statsRecorder.NewMeasureMap(); map.Put(StreamingHubElapsed, elapsed); map.Put(StreamingHubResponseSize, responseSize); if (isErrorOrInterrupted) { map.Put(StreamingHubErrorCount, 1); } map.Record(CreateTag(context)); }
public override async ValueTask Invoke(StreamingHubContext context, Func <StreamingHubContext, ValueTask> next) { // https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/rpc.md#grpc using var activity = source.StartActivity($"{context.ServiceContext.MethodType}:/{context.Path}", ActivityKind.Server); // activity may be null if "no one is listening" or "all listener returns ActivitySamplingResult.None in Sample or SampleUsingParentId callback". if (activity == null) { await next(context); return; } // add trace context to service context. it allows user to add their span directly to this hub context.SetTraceContext(activity.Context); try { // request activity.SetTag("grpc.method", context.ServiceContext.MethodType.ToString()); activity.SetTag("rpc.system", "grpc"); activity.SetTag("rpc.service", context.ServiceContext.ServiceType.Name); activity.SetTag("rpc.method", $"/{context.Path}"); activity.SetTag("net.peer.ip", context.ServiceContext.CallContext.Peer); activity.SetTag("http.host", context.ServiceContext.CallContext.Host); activity.SetTag("http.useragent", context.ServiceContext.CallContext.RequestHeaders.GetValue("user-agent")); activity.SetTag("message.type", "RECIEVED"); activity.SetTag("message.id", context.ServiceContext.ContextId.ToString()); activity.SetTag("message.uncompressed_size", context.Request.Length.ToString()); activity.SetTag("magiconion.peer.ip", context.ServiceContext.CallContext.Peer); activity.SetTag("magiconion.auth.enabled", (!string.IsNullOrEmpty(context.ServiceContext.CallContext.AuthContext.PeerIdentityPropertyName)).ToString()); activity.SetTag("magiconion.auth.peer.authenticated", context.ServiceContext.CallContext.AuthContext.IsPeerAuthenticated.ToString()); await next(context); // response activity.SetTag("grpc.status_code", ((long)context.ServiceContext.CallContext.Status.StatusCode).ToString()); activity.SetStatus(OpenTelemetryHelper.GrpcToOpenTelemetryStatus(context.ServiceContext.CallContext.Status.StatusCode)); } catch (Exception ex) { activity.SetTag("exception", ex.ToString()); activity.SetTag("grpc.status_code", ((long)context.ServiceContext.CallContext.Status.StatusCode).ToString()); activity.SetTag("grpc.status_detail", context.ServiceContext.CallContext.Status.Detail); activity.SetStatus(OpenTelemetryHelper.GrpcToOpenTelemetryStatus(context.ServiceContext.CallContext.Status.StatusCode)); throw; } }
public override async ValueTask Invoke(StreamingHubContext context, Func <StreamingHubContext, ValueTask> next) { // https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/rpc.md#grpc // TracerName must match with ActivitySource name. var tracer = tracerProvider.GetTracer(telemetryOption.ActivitySourceName, telemetryOption.TracerVersion); // Client -> Server incoming filter // span name must be `$package.$service/$method` but MagicOnion has no $package. using (var span = tracer.StartSpan($"{context.ServiceContext.MethodType}:/{context.Path}", SpanKind.Server)) { try { span.SetAttribute("grpc.method", context.ServiceContext.MethodType.ToString()); span.SetAttribute("rpc.system", "grpc"); span.SetAttribute("rpc.service", context.ServiceContext.ServiceType.Name); span.SetAttribute("rpc.method", $"/{context.Path}"); // todo: context.CallContext.Peer/Host format is https://github.com/grpc/grpc/blob/master/doc/naming.md and not uri standard. span.SetAttribute("net.peer.ip", context.ServiceContext.CallContext.Peer); span.SetAttribute("net.host.name", context.ServiceContext.CallContext.Host); span.SetAttribute("message.type", "RECIEVED"); span.SetAttribute("message.id", context.ServiceContext.ContextId.ToString()); span.SetAttribute("message.uncompressed_size", context.Request.Length.ToString()); // todo: net.peer.name not report on tracer. use custom tag span.SetAttribute("magiconion.peer.ip", context.ServiceContext.CallContext.Peer); span.SetAttribute("magiconion.auth.enabled", (!string.IsNullOrEmpty(context.ServiceContext.CallContext.AuthContext.PeerIdentityPropertyName)).ToString()); span.SetAttribute("magiconion.auth.peer.authenticated", context.ServiceContext.CallContext.AuthContext.IsPeerAuthenticated.ToString()); await next(context); span.SetAttribute("grpc.status_code", ((long)context.ServiceContext.CallContext.Status.StatusCode).ToString()); span.Status = OpenTelemetrygRpcStatusHelper.ConvertStatus(context.ServiceContext.CallContext.Status.StatusCode); } catch (Exception ex) { span.SetAttribute("exception", ex.ToString()); span.SetAttribute("grpc.status_code", ((long)context.ServiceContext.CallContext.Status.StatusCode).ToString()); span.SetAttribute("grpc.status_detail", context.ServiceContext.CallContext.Status.Detail); span.Status = OpenTelemetrygRpcStatusHelper.ConvertStatus(context.ServiceContext.CallContext.Status.StatusCode); throw; } } }
public override async ValueTask Invoke(StreamingHubContext context, Func <StreamingHubContext, ValueTask> next) { // https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/rpc.md#grpc using var activity = source.StartActivity($"{context.ServiceContext.MethodType}:/{context.Path}", ActivityKind.Server); // add trace context to service context. it allows user to add their span directly to this hub context.SetTraceContext(activity.Context); try { activity.SetTag("grpc.method", context.ServiceContext.MethodType.ToString()); activity.SetTag("rpc.system", "grpc"); activity.SetTag("rpc.service", context.ServiceContext.ServiceType.Name); activity.SetTag("rpc.method", $"/{context.Path}"); // todo: context.CallContext.Peer/Host format is https://github.com/grpc/grpc/blob/master/doc/naming.md and not uri standard. activity.SetTag("net.peer.ip", context.ServiceContext.CallContext.Peer); activity.SetTag("net.host.name", context.ServiceContext.CallContext.Host); activity.SetTag("message.type", "RECIEVED"); activity.SetTag("message.id", context.ServiceContext.ContextId.ToString()); activity.SetTag("message.uncompressed_size", context.Request.Length.ToString()); // todo: net.peer.name not report on tracer. use custom tag activity.SetTag("magiconion.peer.ip", context.ServiceContext.CallContext.Peer); activity.SetTag("magiconion.auth.enabled", (!string.IsNullOrEmpty(context.ServiceContext.CallContext.AuthContext.PeerIdentityPropertyName)).ToString()); activity.SetTag("magiconion.auth.peer.authenticated", context.ServiceContext.CallContext.AuthContext.IsPeerAuthenticated.ToString()); await next(context); activity.SetTag("grpc.status_code", ((long)context.ServiceContext.CallContext.Status.StatusCode).ToString()); activity.SetStatus(OpenTelemetrygRpcStatusHelper.ConvertStatus(context.ServiceContext.CallContext.Status.StatusCode)); } catch (Exception ex) { activity.SetTag("exception", ex.ToString()); activity.SetTag("grpc.status_code", ((long)context.ServiceContext.CallContext.Status.StatusCode).ToString()); activity.SetTag("grpc.status_detail", context.ServiceContext.CallContext.Status.Detail); activity.SetStatus(OpenTelemetrygRpcStatusHelper.ConvertStatus(context.ServiceContext.CallContext.Status.StatusCode)); throw; } }
public override async ValueTask Invoke(StreamingHubContext context, Func <StreamingHubContext, ValueTask> next) { // https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/rpc.md#grpc // span name must be `$package.$service/$method` but MagicOnion has no $package. var tracer = tracerFactcory.GetTracer($"/{context.Path}"); // incoming kind: SERVER using (tracer.StartActiveSpan($"/{context.Path}", SpanKind.Server, out var span)) { try { span.SetAttribute("rpc.service", serviceName); span.SetAttribute("net.peer.ip", context.ServiceContext.CallContext.Peer); span.SetAttribute("net.host.name", context.ServiceContext.CallContext.Host); span.SetAttribute("message.type", "RECIEVED"); span.SetAttribute("message.id", context.ServiceContext.ContextId.ToString()); span.SetAttribute("message.uncompressed_size", context.Request.Length); span.SetAttribute("magiconion.method.type", context.ServiceContext.MethodType.ToString()); span.SetAttribute("magiconion.service.type", context.ServiceContext.ServiceType.Name); span.SetAttribute("magiconion.auth.enabled", !string.IsNullOrEmpty(context.ServiceContext.CallContext.AuthContext.PeerIdentityPropertyName)); span.SetAttribute("magiconion.auth.peer.authenticated", context.ServiceContext.CallContext.AuthContext.IsPeerAuthenticated); await next(context); span.SetAttribute("grpc.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("grpc.status_code", (long)context.ServiceContext.CallContext.Status.StatusCode); span.Status = OpenTelemetrygRpcStatusHelper.ConvertStatus(context.ServiceContext.CallContext.Status.StatusCode).WithDescription(context.ServiceContext.CallContext.Status.Detail); throw; } } }
public void BeginInvokeHubMethod(StreamingHubContext context, ArraySegment <byte> request, Type type) { GrpcEnvironment.Logger.Debug($"{nameof(BeginInvokeHubMethod)} method:{context.Path} size:{request.Count} {ToJson(request, type, context.FormatterResolver)}"); }
public void BeginInvokeHubMethod(StreamingHubContext context, ArraySegment <byte> request, Type type) { statsRecorder.NewMeasureMap().Put(StreamingHubRequestCount, 1).Record(CreateTag(context)); }
/// <summary> /// Create tags with context and put to metrics /// </summary> /// <param name="context"></param> /// <returns></returns> ITagContext CreateTag(StreamingHubContext context) { return(tagger.ToBuilder(defaultTags).Put(MethodKey, TagValue.Create(context.Path)).Build()); }
public void BeginInvokeHubMethod(StreamingHubContext context, ArraySegment <byte> request, Type type) { }
public void EndInvokeHubMethod(StreamingHubContext context, int responseSize, Type?type, double elapsed, bool isErrorOrInterrupted) { }
public void EndInvokeHubMethod(StreamingHubContext context, int responseSize, Type type, double elapsed, bool isErrorOrInterrupted) { var msg = isErrorOrInterrupted ? "error" : ""; logger.LogDebug($"{nameof(EndInvokeHubMethod)} method:{context.Path} size:{responseSize} elapsed:{elapsed} {msg}"); }
/// <summary> /// Gets the trace context associated with this streaming hub context. /// </summary> /// <param name="context"></param> /// <returns></returns> public static ActivityContext GetTraceContext(this StreamingHubContext context) { return((ActivityContext)context.Items[MagicOnionTelemetry.ServiceContextItemKeyTrace]); }
public void BeginInvokeHubMethod(StreamingHubContext context, ReadOnlyMemory <byte> request, Type type) { _logger.LogDebug($"{nameof(BeginInvokeHubMethod)} method:{context.Path} size:{request.Length} {ToJson(request, context.SerializerOptions)}"); }
public void Error(Exception ex, StreamingHubContext context) { logger.LogError(ex, "Hub Method Handler throws exception occured in " + context.Path); }
public void BeginInvokeHubMethod(StreamingHubContext context, ReadOnlyMemory <byte> request, Type type) { streamingHubRequestCounter.Add(default(SpanContext), 1, CreateLabel(context)); }
public void Error(Exception ex, StreamingHubContext context) { // todo: exception count }
/// <summary> /// Set the trace context with this streaming hub context /// </summary> /// <param name="context"></param> /// <param name="activityContext"></param> internal static void SetTraceContext(this StreamingHubContext context, ActivityContext activityContext) { context.Items[MagicOnionTelemetry.ServiceContextItemKeyTrace] = activityContext; }
public void BeginInvokeHubMethod(StreamingHubContext context, ReadOnlyMemory <byte> request, Type type) { logger.LogDebug($"{nameof(BeginInvokeHubMethod)} method:{context.Path} size:{request.Length}"); }
public void Error(Exception ex, StreamingHubContext context) { }
public void BeginInvokeHubMethod(StreamingHubContext context, ArraySegment <byte> request, Type type) { logger.LogDebug($"{nameof(BeginInvokeHubMethod)} method:{context.Path} size:{request.Count}"); }
public void BeginInvokeHubMethod(StreamingHubContext context, ReadOnlyMemory <byte> request, Type type) { }