Add support for HttpSemanticConvention breaking changes (part2) (#4514)

This commit is contained in:
Timothy Mothra 2023-05-25 15:38:03 -07:00 committed by GitHub
parent f2477584f9
commit 601485d9d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 0 deletions

View File

@ -21,6 +21,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
#endif
using OpenTelemetry.Trace;
using static OpenTelemetry.Internal.HttpSemanticConventionHelper;
namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
{
@ -34,12 +35,16 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
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)

View File

@ -19,6 +19,7 @@ using System.Reflection;
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Instrumentation.Http;
using OpenTelemetry.Trace;
using static OpenTelemetry.Internal.HttpSemanticConventionHelper;
namespace OpenTelemetry.Instrumentation.GrpcNetClient.Implementation
{
@ -36,10 +37,14 @@ namespace OpenTelemetry.Instrumentation.GrpcNetClient.Implementation
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)

View File

@ -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>

View File

@ -21,6 +21,7 @@ using System.Net.Http;
using System.Reflection;
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Trace;
using static OpenTelemetry.Internal.HttpSemanticConventionHelper;
namespace OpenTelemetry.Instrumentation.Http.Implementation
{
@ -45,6 +46,8 @@ namespace OpenTelemetry.Instrumentation.Http.Implementation
private readonly PropertyFetcher<TaskStatus> stopRequestStatusFetcher = new("RequestTaskStatus");
private readonly HttpClientInstrumentationOptions options;
private readonly HttpSemanticConvention httpSemanticConvention;
static HttpHandlerDiagnosticListener()
{
try
@ -61,6 +64,8 @@ namespace OpenTelemetry.Instrumentation.Http.Implementation
: base("HttpHandlerDiagnosticListener")
{
this.options = options;
this.httpSemanticConvention = GetSemanticConventionOptIn();
}
public override void OnEventWritten(string name, object payload)

View File

@ -20,6 +20,7 @@ using System.Diagnostics.Metrics;
using System.Net.Http;
#endif
using OpenTelemetry.Trace;
using static OpenTelemetry.Internal.HttpSemanticConventionHelper;
namespace OpenTelemetry.Instrumentation.Http.Implementation
{
@ -31,10 +32,14 @@ namespace OpenTelemetry.Instrumentation.Http.Implementation
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)

View File

@ -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>

View File

@ -17,6 +17,7 @@
using System.Data;
using System.Diagnostics;
using OpenTelemetry.Trace;
using static OpenTelemetry.Internal.HttpSemanticConventionHelper;
namespace OpenTelemetry.Instrumentation.SqlClient.Implementation
{
@ -40,10 +41,14 @@ namespace OpenTelemetry.Instrumentation.SqlClient.Implementation
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;

View File

@ -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>