From b89dde69b70367d535eaf9db70b603f48f2470e5 Mon Sep 17 00:00:00 2001 From: Gabriel Lucaci Date: Wed, 19 Jan 2022 09:30:46 +0100 Subject: [PATCH] Remove IConfigurationReader dependency and update packages (#22) --- src/Dependencies.props | 4 ++-- .../HotChocolateDiagnosticListener.cs | 13 +++++-------- .../RequestExecutorBuilderExtensions.cs | 8 ++------ 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/Dependencies.props b/src/Dependencies.props index c8d1da9..7f902dd 100644 --- a/src/Dependencies.props +++ b/src/Dependencies.props @@ -1,8 +1,8 @@ - 1.12.0 - 12.0.0 + 1.13.0 + 12.5.0 7.1.0 4.7.0 diff --git a/src/Elastic.Apm.GraphQL.HotChocolate/HotChocolateDiagnosticListener.cs b/src/Elastic.Apm.GraphQL.HotChocolate/HotChocolateDiagnosticListener.cs index 3833300..6f4037e 100644 --- a/src/Elastic.Apm.GraphQL.HotChocolate/HotChocolateDiagnosticListener.cs +++ b/src/Elastic.Apm.GraphQL.HotChocolate/HotChocolateDiagnosticListener.cs @@ -1,13 +1,12 @@ using System; using System.Collections.Generic; using Elastic.Apm.Api; -using Elastic.Apm.Config; +using Elastic.Apm.Logging; using HotChocolate.Execution; using HotChocolate.Execution.Instrumentation; using HotChocolate.Language; using HotChocolate.Resolvers; using IError = HotChocolate.IError; -using LogLevel = Elastic.Apm.Logging.LogLevel; namespace Elastic.Apm.GraphQL.HotChocolate { @@ -15,14 +14,10 @@ internal class HotChocolateDiagnosticListener : ExecutionDiagnosticEventListener { private static readonly string ResolveFieldValueFailed = $"{nameof(ResolveFieldValue)} failed."; - private readonly IConfigurationReader _configuration; private readonly HotChocolateDiagnosticOptions _options; - internal HotChocolateDiagnosticListener( - IConfigurationReader configuration, - HotChocolateDiagnosticOptions options) + internal HotChocolateDiagnosticListener(HotChocolateDiagnosticOptions options) { - _configuration = configuration; _options = options; } @@ -41,7 +36,9 @@ public override IDisposable ExecuteRequest(IRequestContext context) public override IDisposable ResolveFieldValue(IMiddlewareContext context) { - if (_configuration.LogLevel > LogLevel.Debug || !Agent.IsConfigured) + if (!Agent.IsConfigured || + Agent.Tracer.CurrentTransaction == null || + Agent.Tracer.CurrentTransaction.Configuration.LogLevel > LogLevel.Debug) { return EmptyScope; } diff --git a/src/Elastic.Apm.GraphQL.HotChocolate/RequestExecutorBuilderExtensions.cs b/src/Elastic.Apm.GraphQL.HotChocolate/RequestExecutorBuilderExtensions.cs index f683c69..bdba92c 100644 --- a/src/Elastic.Apm.GraphQL.HotChocolate/RequestExecutorBuilderExtensions.cs +++ b/src/Elastic.Apm.GraphQL.HotChocolate/RequestExecutorBuilderExtensions.cs @@ -1,5 +1,4 @@ using System; -using Elastic.Apm.Config; using HotChocolate.Execution.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -22,11 +21,8 @@ public static IRequestExecutorBuilder AddObservability( var options = new HotChocolateDiagnosticOptions(); configure?.Invoke(options); - return builder.AddDiagnosticEventListener(sp => - { - IConfigurationReader configuration = sp.GetApplicationService(); - return new HotChocolateDiagnosticListener(configuration, options); - }); + return builder.AddDiagnosticEventListener(_ => + new HotChocolateDiagnosticListener(options)); } } }