Beispiel #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);
        }
Beispiel #2
0
        private static Scope CreateScopeFromExecuteAsync(object executionContext)
        {
            if (!Tracer.Instance.Settings.IsIntegrationEnabled(IntegrationId))
            {
                // 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;

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

            return(scope);
        }