Exemple #1
0
        private static Scope CreateScopeFromValidate(object document)
        {
            if (!Tracer.Instance.Settings.IsIntegrationEnabled(IntegrationId))
            {
                // integration disabled, don't create a scope, skip this trace
                return(null);
            }

            Tracer tracer = Tracer.Instance;
            string source = document.GetProperty <string>("OriginalQuery")
                            .GetValueOrDefault();
            string serviceName = tracer.Settings.GetServiceName(tracer, ServiceName);

            Scope scope = null;

            try
            {
                var tags = new GraphQLTags();
                scope = tracer.StartActiveWithTags(ValidateOperationName, serviceName: serviceName, tags: tags);
                var span = scope.Span;
                DecorateSpan(span, tags);
                tags.Source = source;

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

            return(scope);
        }
Exemple #2
0
        private static Scope CreateScopeFromExecuteAsync(object executionContext)
        {
            if (!Tracer.Instance.Settings.IsIntegrationEnabled(IntegrationName))
            {
                // integration disabled, don't create a scope, skip this trace
                return(null);
            }

            Tracer tracer = Tracer.Instance;
            string source = executionContext.GetProperty("Document")
                            .GetProperty <string>("OriginalQuery")
                            .GetValueOrDefault();
            string operationName = executionContext.GetProperty("Operation")
                                   .GetProperty <string>("Name")
                                   .GetValueOrDefault();
            string operationType = executionContext.GetProperty("Operation")
                                   .GetProperty <Enum>("OperationType")
                                   .GetValueOrDefault()
                                   .ToString();
            string serviceName = $"{tracer.DefaultServiceName}-{ServiceName}";

            Scope scope = null;

            try
            {
                var tags = new GraphQLTags();
                scope = tracer.StartActiveWithTags(ExecuteOperationName, serviceName: serviceName, tags: tags);
                var span = scope.Span;
                DecorateSpan(span, tags);
                span.ResourceName = $"{operationType} {operationName ?? "operation"}";

                tags.Source        = source;
                tags.OperationName = operationName;
                tags.OperationType = operationType;

                // 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);
        }
Exemple #3
0
 private static void DecorateSpan(Span span, GraphQLTags tags)
 {
     span.Type = SpanTypes.GraphQL;
 }
Exemple #4
0
 private static void DecorateSpan(Span span, GraphQLTags tags)
 {
     span.Type     = SpanTypes.GraphQL;
     tags.SpanKind = SpanKinds.Server;
     tags.Language = TracerConstants.Language;
 }