Esempio n. 1
0
        public static Scope CreateScope(Tracer tracer, string integrationName, object pipeline, object requestData)
        {
            if (!tracer.Settings.IsIntegrationEnabled(integrationName))
            {
                // integration disabled, don't create a scope, skip this trace
                return(null);
            }

            string requestName = pipeline.GetProperty("RequestParameters")
                                 .GetValueOrDefault()
                                 ?.GetType()
                                 .Name
                                 .Replace("RequestParameters", string.Empty);

            var pathAndQuery = requestData.GetProperty <string>("PathAndQuery").GetValueOrDefault() ??
                               requestData.GetProperty <string>("Path").GetValueOrDefault();

            string method = requestData.GetProperty("Method").GetValueOrDefault()?.ToString();
            var    url    = requestData.GetProperty("Uri").GetValueOrDefault()?.ToString();

            var serviceName = $"{tracer.DefaultServiceName}-{ServiceName}";

            Scope scope = null;

            try
            {
                var tags = new ElasticsearchTags();
                scope = tracer.StartActiveWithTags(OperationName, serviceName: serviceName, tags: tags);
                var span = scope.Span;
                span.ResourceName        = requestName ?? pathAndQuery ?? string.Empty;
                span.Type                = SpanType;
                tags.InstrumentationName = ComponentValue;
                tags.SpanKind            = SpanKinds.Client;
                tags.Action              = requestName;
                tags.Method              = method;
                tags.Url = url;

                // set analytics sample rate if enabled
                var analyticsSampleRate = tracer.Settings.GetIntegrationAnalyticsSampleRate(integrationName, enabledWithGlobalSetting: false);

                if (analyticsSampleRate != null)
                {
                    tags.AnalyticsSampleRate = analyticsSampleRate;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error creating or populating scope.");
            }

            return(scope);
        }
Esempio n. 2
0
        public static Scope CreateScope <T>(Tracer tracer, IntegrationInfo integrationId, RequestPipelineStruct pipeline, T requestData)
            where T : IRequestData
        {
            if (!tracer.Settings.IsIntegrationEnabled(integrationId))
            {
                // integration disabled, don't create a scope, skip this trace
                return(null);
            }

            var    requestParameters = pipeline.RequestParameters;
            string requestName       = requestParameters?.GetType().Name.Replace("RequestParameters", string.Empty);

            var pathAndQuery = requestData.Path;

            string method = requestData.Method;
            var    url    = requestData.Uri?.ToString();

            string serviceName = tracer.Settings.GetServiceName(tracer, ServiceName);

            Scope scope = null;

            try
            {
                var tags = new ElasticsearchTags();
                scope = tracer.StartActiveWithTags(OperationName, serviceName: serviceName, tags: tags);
                var span = scope.Span;
                span.ResourceName = requestName ?? pathAndQuery ?? string.Empty;
                span.Type         = SpanType;
                tags.Action       = requestName;
                tags.Method       = method;
                tags.Url          = url;

                tags.SetAnalyticsSampleRate(integrationId, tracer.Settings, enabledWithGlobalSetting: false);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error creating or populating scope.");
            }

            return(scope);
        }