Skip to content

Commit

Permalink
Remove IConfigurationReader dependency and update packages (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
glucaci authored Jan 19, 2022
1 parent 087b17f commit b89dde6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Dependencies.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>

<PropertyGroup>
<ElasticApmVersion>1.12.0</ElasticApmVersion>
<HotChocolateVersion>12.0.0</HotChocolateVersion>
<ElasticApmVersion>1.13.0</ElasticApmVersion>
<HotChocolateVersion>12.5.0</HotChocolateVersion>
<MassTransitVersion>7.1.0</MassTransitVersion>
<SystemDiagnosticSourceVersion>4.7.0</SystemDiagnosticSourceVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
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
{
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;
}

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Elastic.Apm.Config;
using HotChocolate.Execution.Configuration;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -22,11 +21,8 @@ public static IRequestExecutorBuilder AddObservability(
var options = new HotChocolateDiagnosticOptions();
configure?.Invoke(options);

return builder.AddDiagnosticEventListener(sp =>
{
IConfigurationReader configuration = sp.GetApplicationService<IConfigurationReader>();
return new HotChocolateDiagnosticListener(configuration, options);
});
return builder.AddDiagnosticEventListener(_ =>
new HotChocolateDiagnosticListener(options));
}
}
}

0 comments on commit b89dde6

Please sign in to comment.