private static void ServiceRemotingServiceEvents_ReceiveRequest(object?sender, EventArgs?e)
        {
            var tracer = Tracer.Instance;

            if (!_initialized || !tracer.Settings.IsIntegrationEnabled(ServiceRemotingConstants.IntegrationId))
            {
                return;
            }

            ServiceRemotingHelpers.GetMessageHeaders(e, out var eventArgs, out var messageHeaders);
            SpanContext?spanContext = null;

            try
            {
                // extract propagation context from message headers for distributed tracing
                if (messageHeaders != null)
                {
                    spanContext = SpanContextPropagator.Instance.Extract(messageHeaders, GetHeaders);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error extracting span context from Service Fabric Service Remoting message headers.");
            }

            try
            {
                var span = ServiceRemotingHelpers.CreateSpan(tracer, spanContext, SpanKinds.Server, eventArgs, messageHeaders);
                tracer.ActivateSpan(span);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error creating or activating new Service Fabric Service Remoting service span.");
            }
        }
        private static void ServiceRemotingServiceEvents_SendResponse(object?sender, EventArgs?e)
        {
            if (!_initialized || !Tracer.Instance.Settings.IsIntegrationEnabled(ServiceRemotingConstants.IntegrationId))
            {
                return;
            }

            ServiceRemotingHelpers.FinishSpan(e, SpanKinds.Server);
        }
Exemple #3
0
 public static void StartTracing()
 {
     // only run this code once
     if (Interlocked.Exchange(ref _firstInitialization, 0) == 1)
     {
         // try to subscribe to service events
         if (ServiceRemotingHelpers.AddEventHandler(ServiceRemotingConstants.ServiceEventsTypeName, ServiceRemotingConstants.ReceiveRequestEventName, ServiceRemotingServiceEvents_ReceiveRequest) &&
             ServiceRemotingHelpers.AddEventHandler(ServiceRemotingConstants.ServiceEventsTypeName, ServiceRemotingConstants.SendResponseEventName, ServiceRemotingServiceEvents_SendResponse))
         {
             // don't handle any service events until we have subscribed to both of them
             _initialized = true;
             Log.Debug($"Subscribed to {ServiceRemotingConstants.ServiceEventsTypeName} events.");
         }
     }
 }
Exemple #4
0
        private static void ServiceRemotingServiceEvents_ReceiveRequest(object?sender, EventArgs?e)
        {
            var tracer = Tracer.Instance;

            if (!_initialized || !tracer.Settings.IsIntegrationEnabled(ServiceRemotingConstants.IntegrationId))
            {
                return;
            }

            ServiceRemotingHelpers.GetMessageHeaders(e, out var eventArgs, out var messageHeaders);
            SpanContext?spanContext = null;

            try
            {
                // extract propagation context from message headers for distributed tracing
                if (messageHeaders != null)
                {
                    spanContext = SpanContextPropagator.Instance.Extract(messageHeaders, static (headers, headerName) =>
Exemple #5
0
        private static void ServiceRemotingClientEvents_SendRequest(object?sender, EventArgs?e)
        {
            var tracer = Tracer.Instance;

            if (!_initialized || !tracer.Settings.IsIntegrationEnabled(ServiceRemotingConstants.IntegrationId))
            {
                return;
            }

            ServiceRemotingHelpers.GetMessageHeaders(e, out var eventArgs, out var messageHeaders);

            try
            {
                var span = ServiceRemotingHelpers.CreateSpan(tracer, context: null, SpanKinds.Client, eventArgs, messageHeaders);

                try
                {
                    // inject propagation context into message headers for distributed tracing
                    if (messageHeaders != null)
                    {
                        SpanContextPropagator.Instance.Inject(
                            span.Context,
                            messageHeaders,
                            static (headers, headerName, headerValue) => headers.TryAddHeader(headerName, headerValue));
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error injecting span context into Service Fabric Service Remoting message headers.");
                }

                tracer.ActivateSpan(span);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error creating or activating Service Fabric Service Remoting client span.");
            }
        }