public IScope CreateServerSpan(ServerCallContext context) { _ = context ?? throw new ArgumentNullException(nameof(context)); var operationName = context.Method.Split('/').Last(); ISpanBuilder spanBuilder = null; try { var headers = context.RequestHeaders.ToDictionary(x => x.Key, x => x.Value); ISpanContext parentSpanCtx = _tracer.Extract(BuiltinFormats.HttpHeaders, new TextMapExtractAdapter(headers)); spanBuilder = _tracer.BuildSpan(operationName); spanBuilder = parentSpanCtx != null?spanBuilder.AsChildOf(parentSpanCtx) : spanBuilder; } finally { if (spanBuilder == null) { spanBuilder = _tracer.BuildSpan(operationName); } } return (spanBuilder .WithTag(Tags.SpanKind, Tags.SpanKindServer) .WithTag(Tags.PeerHostname, context.Host) .WithTag("correlation-id", GetCorrelationId()) .StartActive(true)); }
private IScope BuildServerScope(HttpContext context) { ISpanBuilder spanBuilder = null; var operationName = GetOperationName(context); var requestTraceHeaders = context.GetTraceHeaders(); if (requestTraceHeaders?.Any() ?? false) { try { spanBuilder = _tracer.BuildSpan(operationName); var parentSpanContext = _tracer.Extract(BuiltinFormats.TextMap, new TextMapExtractAdapter(requestTraceHeaders)); if (parentSpanContext != null) { spanBuilder = spanBuilder.AsChildOf(parentSpanContext); } } catch { } } if (spanBuilder == null) { spanBuilder = _tracer.BuildSpan(operationName); } return(spanBuilder.WithTag(Tags.SpanKind, Tags.SpanKindServer).StartActive(true)); }
public ISpan TraceOperation(string operationName) { IScope activeScope = Tracer.ScopeManager.Active; ISpanBuilder spanBuilder = Tracer.BuildSpan(operationName); return(activeScope?.Span is null ? spanBuilder.StartActive(true).Span : spanBuilder .AsChildOf(Tracer.ScopeManager.Active.Span) .Start()); }
private ISpan BuildNewSpanWithDefaultTags(CommandStartedEvent @event) { IScope activeScope = _tracer.ScopeManager.Active; ISpanBuilder span = _tracer .BuildSpan($"{CallistoConstants.TracerPrefix}-{MongoCommandHelper.NormalizeCommandName(@event.CommandName)}") .WithTag(Tags.SpanKind, Tags.SpanKindClient) .WithTag(Tags.Component, "Solari.Callisto") .WithTag(Tags.DbStatement, SanitateDbStatement(@event.Command.ToString())) .WithTag(Tags.DbInstance, @event.DatabaseNamespace.DatabaseName) .WithTag("mongodb.host", @event.ConnectionId.ServerId.EndPoint.ToString()) .WithTag("mongodb.host.clusterid", @event.ConnectionId.ServerId.ClusterId.ToString()) .WithTag(Tags.DbType, "MongoDb"); return(activeScope?.Span == null?span.Start() : span.AsChildOf(_tracer.ScopeManager.Active.Span).Start()); }
public OpenTracingExtensionsTests() { _spanContext = Substitute.For <ISpanContext>(); _span = Substitute.For <ISpan>(); _span.Context.Returns(_spanContext); _scope = Substitute.For <IScope>(); _scope.Span.Returns(_span); _spanBuilder = Substitute.For <ISpanBuilder>(); _spanBuilder.AsChildOf(Arg.Any <ISpan>()).Returns(_spanBuilder); _spanBuilder.StartActive().Returns(_scope); _spanBuilder.StartActive(Arg.Any <bool>()).ReturnsForAnyArgs(_scope); _tracer = Substitute.For <ITracer>(); _tracer.BuildSpan("").ReturnsForAnyArgs(_spanBuilder); }
public ISpanBuilder AsChildOf(ISpan parent) { return(_innerSpanBuilder.AsChildOf(parent)); }
public virtual ISpanBuilder AsChildOf(ISpanContext parent) { _spanBuilder.AsChildOf(parent); return(this); }