/// <summary> /// Initializes a new instance of the <see cref="ServerRpcScope{TRequest, TResponse}"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="options">The options.</param> public ServerRpcScope(ServerCallContext context, ServerTracingInterceptorOptions options) : base(context.Method, options.RecordMessageEvents) { if (!GrpcCoreInstrumentation.ActivitySource.HasListeners()) { return; } var currentContext = Activity.Current?.Context; // Extract the SpanContext, if any from the headers var metadata = context.RequestHeaders; if (metadata != null) { var propagationContext = options.Propagator.Extract(new PropagationContext(currentContext ?? default, Baggage.Current), metadata, MetadataGetter); if (propagationContext.ActivityContext.IsValid()) { currentContext = propagationContext.ActivityContext; } if (propagationContext.Baggage != default) { Baggage.Current = propagationContext.Baggage; } } // This if block is for unit testing only. IEnumerable <KeyValuePair <string, object> > customTags = null; if (options.ActivityIdentifierValue != default) { customTags = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(SemanticConventions.AttributeActivityIdentifier, options.ActivityIdentifierValue), }; } var activity = GrpcCoreInstrumentation.ActivitySource.StartActivity( this.FullServiceName, ActivityKind.Server, currentContext ?? default, tags: customTags); this.SetActivity(activity); }
/// <summary> /// Initializes a new instance of the <see cref="ServerTracingInterceptor"/> class. /// </summary> /// <param name="options">The options.</param> public ServerTracingInterceptor(ServerTracingInterceptorOptions options) { this.options = options ?? throw new ArgumentNullException(nameof(options)); }