public override void OnStartActivity(Activity activity, object payload)
        {
            // By this time, samplers have already run and
            // activity.IsAllDataRequested populated accordingly.

            if (Sdk.SuppressInstrumentation)
            {
                return;
            }

            if (activity.IsAllDataRequested)
            {
                if (this.options.TracedOperations != null && !this.options.TracedOperations.Contains(activity.OperationName))
                {
                    MassTransitInstrumentationEventSource.Log.RequestIsFilteredOut(activity.OperationName);
                    activity.IsAllDataRequested = false;
                    return;
                }

                activity.DisplayName = this.GetDisplayName(activity);

                ActivityInstrumentationHelper.SetActivitySourceProperty(activity, ActivitySource);
                ActivityInstrumentationHelper.SetKindProperty(activity, this.GetActivityKind(activity));
            }
        }
コード例 #2
0
        public override void OnStartActivity(Activity activity, object payload)
        {
            if (activity.IsAllDataRequested)
            {
                if (!this.options.TracedOperations.Contains(activity.OperationName))
                {
                    QuartzInstrumentationEventSource.Log.OperationIsFilteredOut(activity.OperationName);
                    activity.IsAllDataRequested = false;
                    return;
                }

                activity.DisplayName = this.GetDisplayName(activity);

                ActivityInstrumentationHelper.SetActivitySourceProperty(activity, ActivitySource);
                ActivityInstrumentationHelper.SetKindProperty(activity, this.GetActivityKind(activity));

                try
                {
                    this.JobDetailsPropertyFetcher.TryFetch(payload, out var jobDetails);
                    this.options.Enrich?.Invoke(activity, "OnStartActivity", jobDetails);
                }
                catch (Exception ex)
                {
                    QuartzInstrumentationEventSource.Log.EnrichmentException(ex);
                }
            }
        }
コード例 #3
0
        public void SetActivityKind(ActivityKind activityKind)
        {
            var activity = new Activity("Test");

            activity.Start();
            ActivityInstrumentationHelper.SetKindProperty(activity, activityKind);
            Assert.Equal(activityKind, activity.Kind);
        }
        public override void OnStartActivity(Activity activity, object payload)
        {
            var uri = this.uriFetcher.Fetch(payload);

            if (uri == null)
            {
                ElasticsearchInstrumentationEventSource.Log.NullPayload(nameof(ElasticsearchRequestPipelineDiagnosticListener), nameof(this.OnStartActivity));
                return;
            }

            ActivityInstrumentationHelper.SetActivitySourceProperty(activity, ActivitySource);
            ActivityInstrumentationHelper.SetKindProperty(activity, ActivityKind.Client);

            var method = this.methodFetcher.Fetch(payload);

            activity.DisplayName = this.GetDisplayName(activity, method);

            if (this.options.SuppressDownstreamInstrumentation)
            {
                SuppressInstrumentationScope.Enter();
            }

            if (!activity.IsAllDataRequested)
            {
                return;
            }

            var elasticIndex = this.GetElasticIndex(uri);

            activity.DisplayName = this.GetDisplayName(activity, method, elasticIndex);
            activity.SetTag(SemanticConventions.AttributeDbSystem, DatabaseSystemName);

            if (elasticIndex != null)
            {
                activity.SetTag(SemanticConventions.AttributeDbName, elasticIndex);
            }

            var uriHostNameType = Uri.CheckHostName(uri.Host);

            if (uriHostNameType == UriHostNameType.IPv4 || uriHostNameType == UriHostNameType.IPv6)
            {
                activity.SetTag(SemanticConventions.AttributeNetPeerIp, uri.Host);
            }
            else
            {
                activity.SetTag(SemanticConventions.AttributeNetPeerName, uri.Host);
            }

            if (uri.Port > 0)
            {
                activity.SetTag(SemanticConventions.AttributeNetPeerPort, uri.Port);
            }

            if (method != null)
            {
                activity.SetTag(AttributeDbMethod, method.ToString());
            }

            activity.SetTag(SemanticConventions.AttributeDbUrl, uri.OriginalString);

            try
            {
                this.options.Enrich?.Invoke(activity, "OnStartActivity", payload);
            }
            catch (Exception ex)
            {
                ElasticsearchInstrumentationEventSource.Log.EnrichmentException(ex);
            }
        }
コード例 #5
0
        public override void OnStartActivity(Activity activity, object payload)
        {
            // The overall flow of what GrpcClient library does is as below:
            // Activity.Start()
            // DiagnosticSource.WriteEvent("Start", payload)
            // DiagnosticSource.WriteEvent("Stop", payload)
            // Activity.Stop()

            // This method is in the WriteEvent("Start", payload) path.
            // By this time, samplers have already run and
            // activity.IsAllDataRequested populated accordingly.

            if (Sdk.SuppressInstrumentation)
            {
                return;
            }

            // Ensure context propagation irrespective of sampling decision
            if (!this.startRequestFetcher.TryFetch(payload, out HttpRequestMessage request) || request == null)
            {
                GrpcInstrumentationEventSource.Log.NullPayload(nameof(GrpcClientDiagnosticListener), nameof(this.OnStartActivity));
                return;
            }

            if (this.options.SuppressDownstreamInstrumentation)
            {
                SuppressInstrumentationScope.Enter();

                // If we are suppressing downstream instrumentation then inject
                // context here. Grpc.Net.Client uses HttpClient, so
                // SuppressDownstreamInstrumentation means that the
                // OpenTelemetry instrumentation for HttpClient will not be
                // invoked.

                // Note that HttpClient natively generates its own activity and
                // propagates W3C trace context headers regardless of whether
                // OpenTelemetry HttpClient instrumentation is invoked.
                // Therefore, injecting here preserves more intuitive span
                // parenting - i.e., the entry point span of a downstream
                // service would be parented to the span generated by
                // Grpc.Net.Client rather than the span generated natively by
                // HttpClient. Injecting here also ensures that baggage is
                // propagated to downstream services.
                // Injecting context here also ensures that the configured
                // propagator is used, as HttpClient by itself will only
                // do TraceContext propagation.
                var textMapPropagator = Propagators.DefaultTextMapPropagator;
                textMapPropagator.Inject(
                    new PropagationContext(activity.Context, Baggage.Current),
                    request,
                    HttpRequestMessageContextPropagation.HeaderValueSetter);
            }

            if (activity.IsAllDataRequested)
            {
                ActivityInstrumentationHelper.SetActivitySourceProperty(activity, ActivitySource);
                ActivityInstrumentationHelper.SetKindProperty(activity, ActivityKind.Client);

                var grpcMethod = GrpcTagHelper.GetGrpcMethodFromActivity(activity);

                activity.DisplayName = grpcMethod?.Trim('/');

                activity.SetTag(SemanticConventions.AttributeRpcSystem, GrpcTagHelper.RpcSystemGrpc);

                if (GrpcTagHelper.TryParseRpcServiceAndRpcMethod(grpcMethod, out var rpcService, out var rpcMethod))
                {
                    activity.SetTag(SemanticConventions.AttributeRpcService, rpcService);
                    activity.SetTag(SemanticConventions.AttributeRpcMethod, rpcMethod);

                    // Remove the grpc.method tag added by the gRPC .NET library
                    activity.SetTag(GrpcTagHelper.GrpcMethodTagName, null);
                }

                var uriHostNameType = Uri.CheckHostName(request.RequestUri.Host);
                if (uriHostNameType == UriHostNameType.IPv4 || uriHostNameType == UriHostNameType.IPv6)
                {
                    activity.SetTag(SemanticConventions.AttributeNetPeerIp, request.RequestUri.Host);
                }
                else
                {
                    activity.SetTag(SemanticConventions.AttributeNetPeerName, request.RequestUri.Host);
                }

                activity.SetTag(SemanticConventions.AttributeNetPeerPort, request.RequestUri.Port);

                try
                {
                    this.options.Enrich?.Invoke(activity, "OnStartActivity", request);
                }
                catch (Exception ex)
                {
                    GrpcInstrumentationEventSource.Log.EnrichmentException(ex);
                }
            }
        }