Esempio n. 1
0
        public static ActivityContextStub CreateNew(ulong traceId, ulong spanId, bool isSampled, string traceState = null, bool isRemote = false)
        {
            string w3cId = CreateW3CId(traceId, spanId, isSampled);

            if (w3cId == null)
            {
                return(default(ActivityContextStub));
            }

            var aCtx = new ActivityContextStub(w3cId, traceState, isRemote);

            return(aCtx);
        }
Esempio n. 2
0
                public static string CreateW3CId(ulong datadogTraceId, ulong datadogSpanId, bool isSampled)
                {
                    string w3cId;

                    unsafe
                    {
                        char *template = stackalloc char[55] {
                            '0', '0', '-',
                            'd', 'a', '7', 'a', 'd', '0', '9', '0', '0', '0', '0', '0', '0', '0', '0', '0',
                            '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '-',
                            '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '-',
                            '0', '0'
                        };
                        w3cId = ActivityContextStub.CreateW3CIdCore(datadogTraceId, datadogSpanId, isSampled, template);
                    }

                    return(w3cId);
                }
Esempio n. 3
0
        public static ActivityStub StartNewActivity(string operationName,
                                                    ActivityKindStub activityKind,
                                                    ActivityContextStub parentContext,
                                                    IEnumerable <KeyValuePair <string, string> > tags)
        {
            if (!DynamicLoader.EnsureInitialized())
            {
                return(NoOpSingeltons.ActivityStub);
            }

            DynamicInvokerOld invoker = DynamicLoader.Invoker;

            if (invoker.SupportedFeatures.FeatureSet_5000)
            {
                object       activityInstance = invoker.ActivitySource.StartActivity(operationName, activityKind, parentContext, tags);
                ActivityStub activityStub     = Wrap(activityInstance);

                return(activityStub);
            }
            else if (invoker.SupportedFeatures.FeatureSet_4020)
            {
                object       activityInstance = invoker.Activity.Ctor(operationName);
                ActivityStub activityStub     = Wrap(activityInstance);

                // Older Activity versions do not have a concept of Trace and Span. Instead they have an Id and a RoodId.
                // We will generate a parent Id to match the logic employed by older activities so that RoodId acts as a TraceId.
                // See:
                // https://github.com/dotnet/runtime/blob/7666224cfcfb4349da28f9f7fb1de931528ef208/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs#L39
                // https://github.com/dotnet/runtime/blob/7666224cfcfb4349da28f9f7fb1de931528ef208/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs#L358
                // https://github.com/dotnet/runtime/blob/7666224cfcfb4349da28f9f7fb1de931528ef208/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs#L405
                // https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/ActivityUserGuide.md#id-format

                if (parentContext.IsNotInitialized())
                {
                    string parentId = "|" + parentContext.TraceIdHexString + "." + parentContext.SpanIdHexString + "_";
                    invoker.Activity.SetParentId(activityInstance, parentId);
                }

                // Internal is the default. For internal, we avoid creating supplemantal data.
                if (activityKind != ActivityKindStub.Internal)
                {
                    SupplementalActivityData supplementalData = activityStub.GetOrCreateSupplementalData();
                    supplementalData.ActivityKind = activityKind;
                }

                if (tags != null)
                {
                    foreach (KeyValuePair <string, string> tag in tags)
                    {
                        invoker.Activity.AddTag(activityInstance, tag.Key, tag.Value);
                    }
                }

                object diagnosticSource = invoker.DiagnosticListener.DefaultDiagnosticSource;
                invoker.DiagnosticListener.StartActivity(activityInstance, activityInstance);

                return(activityStub);
            }
            else
            {
                string errMsg = FormatNotSupportedErrorMessage($"{nameof(StartNewActivity)}(..)", "4020", invoker);
                throw new NotSupportedException(errMsg);
            }
        }
Esempio n. 4
0
 public static ActivityStub StartNewActivity(string operationName, ActivityKindStub activityKind, ActivityContextStub parentContext)
 {
     return(StartNewActivity(operationName, ActivityKindStub.Internal, parentContext, tags: null));
 }
 internal object StartActivity(string operationName, ActivityKindStub activityKind, ActivityContextStub parentContext, IEnumerable <KeyValuePair <string, string> > tags)
 {
     throw new NotImplementedException();
 }