public bool TryFind(string assemblyName, out Entry packagedAssemblyInfo)
        {
            packagedAssemblyInfo = null;

            if (_assemblies == null || !DynamicLoader.TryParseAssemblyName(assemblyName, out AssemblyName lookupAssemblyName))
            {
                return(false);
            }

            foreach (Entry asmInfo in _assemblies)
            {
                if (IsMatch(lookupAssemblyName, asmInfo.AssemblyName))
                {
                    packagedAssemblyInfo = asmInfo;
                    return(true);
                }
            }

            return(false);
        }
示例#2
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);
            }
        }
 public static bool EnsureInitialized()
 {
     return(DynamicLoader.EnsureInitialized());
 }