示例#1
0
 internal static ISpanBuilder AddDefaultTags(this ISpanBuilder builder)
 {
     return(builder
            .WithTag(Tags.Component, ClientIdentifier.GetClientDescription())
            .WithTag(Tags.DbType, CouchbaseTags.DbTypeCouchbase)
            .WithTag(Tags.SpanKind, Tags.SpanKindClient));
 }
示例#2
0
        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));
        }
 /// <remarks>
 /// <see cref="CallerLineNumberAttribute"/> is explicitly NOT used, since that can change
 /// over time and is likely not valid as a 'Tag' on a <see cref="ISpan"/>, since 'Tag's are
 /// meant to apply to the entirety of the span. Instead, see <see cref="ISpan.Log(IEnumerable{KeyValuePair{string,object}})"/>
 /// options like <see cref="SpanExtensions.LogMemberInfo"/>.
 /// </remarks>
 public static ISpanBuilder WithCallerMemberNameTag(
     this ISpanBuilder spanBuilder,
     string tagName = Constants.CallerMemberNameTagName,
     [CallerMemberName] string callerMemberName = null)
 {
     return(spanBuilder
            .WithTag(tagName, callerMemberName));
 }
示例#5
0
        public static ISpanBuilder WithBusinessId(this ISpanBuilder builder, string aid)
        {
            if (string.IsNullOrEmpty(aid))
            {
                throw new ArgumentException(nameof(aid));
            }

            return(builder.WithTag(OpenTracingConstants.BUSINESS_ID_TAG, aid));
        }
        private void HandleActivityStart(string eventName, Activity activity, object untypedArg, IEnumerable <KeyValuePair <string, string> > tags)
        {
            ISpanBuilder spanBuilder = _tracer.BuildSpan(activity.OperationName)
                                       .WithTag(Tags.Component, _listenerName);

            foreach (var tag in activity.Tags)
            {
                spanBuilder.WithTag(tag.Key, tag.Value);
            }

            if (tags != null)
            {
                foreach (var tag in tags)
                {
                    spanBuilder.WithTag(tag.Key, tag.Value);
                }
            }

            spanBuilder.StartActive();
        }
示例#7
0
        private void HandleActivityStart(string eventName, Activity activity, object untypedArg)
        {
            ISpanBuilder spanBuilder = _tracer.BuildSpan(activity.OperationName)
                                       .WithTag(Tags.Component, _listenerName);

            foreach (var tag in activity.Tags)
            {
                spanBuilder.WithTag(tag.Key, tag.Value);
            }

            spanBuilder.StartActive();
        }
        /// <summary>
        /// Uses reflection over the anonymous type defined by <typeparamref name="T"/>
        /// (via <paramref name="anonymousType"/>) to set each field of <typeparamref name="T"/>
        /// as a tag on <paramref name="spanBuilder"/> (by using <see cref="object.ToString()"/>)
        /// </summary>
        public static ISpanBuilder WithTagsFromAnonymousType <T>(
            this ISpanBuilder spanBuilder,
            T anonymousType)
        {
            foreach (var fieldInfo in AnonymousTypeReflectionCache <T> .Instance.FieldNamesAndGetters)
            {
                var fieldName   = fieldInfo.Key;
                var fieldGetter = fieldInfo.Value;

                var fieldValue = fieldGetter(anonymousType);

                spanBuilder = spanBuilder
                              .WithTag(fieldName, fieldValue);
            }

            return(spanBuilder);
        }
        public void TraceEnter(
            string methodInfo,
            Tuple <string, string>[] configParameters,
            string[] paramNames,
            object[] paramValues)
        {
            if (!GlobalTracer.IsRegistered())
            {
                // Not locking on this check, it's okay to log a few times
                if (!loggedTraceEnterError)
                {
                    loggedTraceEnterError = true;
                    Trace.TraceError(Error.TracerNotRegisteredOnEnter);
                }

                return;
            }

            ISpanBuilder spanBuilder = GlobalTracer.Instance
                                       .BuildSpan($"{this.name}{methodInfo}");

            // Add arguments (if configured to)
            {
                if (ShouldIncludeArguments(configParameters))
                {
                    for (int paramIndex = 0; paramIndex < paramNames.Length; paramIndex++)
                    {
                        string paramName  = paramNames[paramIndex];
                        object paramValue = paramValues[paramIndex];
                        // TODO: Support other forms of serialization
                        string serializedParamValue = paramValue?.ToString();

                        spanBuilder = spanBuilder
                                      .WithTag(paramName, serializedParamValue);
                    }
                }
            }

            spanBuilder
            .StartActive();
        }
示例#10
0
 public ISpanBuilder WithTag(string key, string value)
 {
     return(_innerSpanBuilder.WithTag(key, value));
 }
示例#11
0
 internal static ISpanBuilder WithIgnoreTag(this ISpanBuilder builder)
 {
     return(builder.WithTag(CouchbaseTags.Ignore, true));
 }