Skip to content

Commit

Permalink
Add support for HttpSemanticConvention breaking changes (part2) (#4514)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMothra authored May 25, 2023
1 parent f247758 commit 601485d
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Microsoft.AspNetCore.Routing;
#endif
using OpenTelemetry.Trace;
using static OpenTelemetry.Internal.HttpSemanticConventionHelper;

namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
{
Expand All @@ -34,12 +35,16 @@ internal sealed class HttpInMetricsListener : ListenerHandler
private readonly AspNetCoreMetricsInstrumentationOptions options;
private readonly Histogram<double> httpServerDuration;

private readonly HttpSemanticConvention httpSemanticConvention;

internal HttpInMetricsListener(string name, Meter meter, AspNetCoreMetricsInstrumentationOptions options)
: base(name)
{
this.meter = meter;
this.options = options;
this.httpServerDuration = meter.CreateHistogram<double>(HttpServerDurationMetricName, "ms", "Measures the duration of inbound HTTP requests.");

this.httpSemanticConvention = GetSemanticConventionOptIn();
}

public override void OnEventWritten(string name, object payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Instrumentation.Http;
using OpenTelemetry.Trace;
using static OpenTelemetry.Internal.HttpSemanticConventionHelper;

namespace OpenTelemetry.Instrumentation.GrpcNetClient.Implementation
{
Expand All @@ -36,10 +37,14 @@ internal sealed class GrpcClientDiagnosticListener : ListenerHandler
private readonly PropertyFetcher<HttpRequestMessage> startRequestFetcher = new("Request");
private readonly PropertyFetcher<HttpResponseMessage> stopRequestFetcher = new("Response");

private readonly HttpSemanticConvention httpSemanticConvention;

public GrpcClientDiagnosticListener(GrpcClientInstrumentationOptions options)
: base("Grpc.Net.Client")
{
this.options = options;

this.httpSemanticConvention = GetSemanticConventionOptIn();
}

public override void OnEventWritten(string name, object payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.Http\HttpRequestMessageContextPropagation.cs" Link="Includes\HttpRequestMessageContextPropagation.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\Guard.cs" Link="Includes\Guard.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\HttpSemanticConventionHelper.cs" Link="Includes\HttpSemanticConventionHelper.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Reflection;
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Trace;
using static OpenTelemetry.Internal.HttpSemanticConventionHelper;

namespace OpenTelemetry.Instrumentation.Http.Implementation
{
Expand All @@ -45,6 +46,8 @@ internal sealed class HttpHandlerDiagnosticListener : ListenerHandler
private readonly PropertyFetcher<TaskStatus> stopRequestStatusFetcher = new("RequestTaskStatus");
private readonly HttpClientInstrumentationOptions options;

private readonly HttpSemanticConvention httpSemanticConvention;

static HttpHandlerDiagnosticListener()
{
try
Expand All @@ -61,6 +64,8 @@ public HttpHandlerDiagnosticListener(HttpClientInstrumentationOptions options)
: base("HttpHandlerDiagnosticListener")
{
this.options = options;

this.httpSemanticConvention = GetSemanticConventionOptIn();
}

public override void OnEventWritten(string name, object payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Net.Http;
#endif
using OpenTelemetry.Trace;
using static OpenTelemetry.Internal.HttpSemanticConventionHelper;

namespace OpenTelemetry.Instrumentation.Http.Implementation
{
Expand All @@ -31,10 +32,14 @@ internal sealed class HttpHandlerMetricsDiagnosticListener : ListenerHandler
private readonly PropertyFetcher<HttpRequestMessage> stopRequestFetcher = new("Request");
private readonly Histogram<double> httpClientDuration;

private readonly HttpSemanticConvention httpSemanticConvention;

public HttpHandlerMetricsDiagnosticListener(string name, Meter meter)
: base(name)
{
this.httpClientDuration = meter.CreateHistogram<double>("http.client.duration", "ms", "Measures the duration of outbound HTTP requests.");

this.httpSemanticConvention = GetSemanticConventionOptIn();
}

public override void OnEventWritten(string name, object payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\Guard.cs" Link="Includes\Guard.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\HttpSemanticConventionHelper.cs" Link="Includes\HttpSemanticConventionHelper.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Data;
using System.Diagnostics;
using OpenTelemetry.Trace;
using static OpenTelemetry.Internal.HttpSemanticConventionHelper;

namespace OpenTelemetry.Instrumentation.SqlClient.Implementation
{
Expand All @@ -40,10 +41,14 @@ internal sealed class SqlClientDiagnosticListener : ListenerHandler
private readonly PropertyFetcher<Exception> exceptionFetcher = new("Exception");
private readonly SqlClientInstrumentationOptions options;

private readonly HttpSemanticConvention httpSemanticConvention;

public SqlClientDiagnosticListener(string sourceName, SqlClientInstrumentationOptions options)
: base(sourceName)
{
this.options = options ?? new SqlClientInstrumentationOptions();

this.httpSemanticConvention = GetSemanticConventionOptIn();
}

public override bool SupportsNullActivity => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\Guard.cs" Link="Includes\Guard.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\HttpSemanticConventionHelper.cs" Link="Includes\HttpSemanticConventionHelper.cs" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 601485d

Please sign in to comment.