Skip to content

Commit

Permalink
Merge branch 'main' into utpilla/Update-MetricPoint-Reclaim-To-OptIn-…
Browse files Browse the repository at this point in the history
…Feature
  • Loading branch information
utpilla authored Nov 16, 2023
2 parents 67ddb89 + bdd931e commit 91424a9
Show file tree
Hide file tree
Showing 47 changed files with 258 additions and 242 deletions.
36 changes: 18 additions & 18 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,32 @@
This section covers packages that are **not** directly referenced by the NuGet packages published from this repository.
For example, these packages are used in the tests, examples or referenced as "PrivateAssets", but not in the NuGet packages themselves.
-->
<!-- 'net7.0' is the default `TargetFramework`. Use `VersionOverride` in the project to override the package versions from a different `TargetFramework` -->
<!-- 'net8.0' is the default `TargetFramework`. Use `VersionOverride` in the project to override the package versions from a different `TargetFramework` -->
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="[0.13.10,0.14)" />
<PackageVersion Include="CommandLineParser" Version="[2.9.1,3.0)" />
<PackageVersion Include="Grpc.AspNetCore" Version="[2.55.0,3.0)" />
<PackageVersion Include="Grpc.AspNetCore.Server" Version="[2.55.0, 3.0)" />
<PackageVersion Include="Grpc.Tools" Version="[2.56.2,3.0)" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="[3.11.0-beta1.23402.2]" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="2.1.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="[3.1.6,5.0)" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="3.1.20" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="[6.0.0,)" />
<PackageVersion Include="Grpc.AspNetCore" Version="[2.59.0,3.0)" />
<PackageVersion Include="Grpc.AspNetCore.Server" Version="[2.59.0, 3.0)" />
<PackageVersion Include="Grpc.Tools" Version="[2.59.0,3.0)" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="[3.11.0-beta1.23525.2]" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="[8.0.0,)" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="[8.0.0,)" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="[8.0.0,)" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="[8.0.0,)" />
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="[1.0.3,2.0)" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="[17.7.2,18.0.0)" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="[17.8.0,18.0.0)" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="[1.1.1,2.0)" />
<PackageVersion Include="MinVer" Version="[4.3.0,5.0)" />
<PackageVersion Include="Moq" Version="[4.18.4,5.0)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="[1.5.0,2.0)" />
<PackageVersion Include="RabbitMQ.Client" Version="[6.5.0,7.0)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="[1.5.1,2.0)" />
<PackageVersion Include="RabbitMQ.Client" Version="[6.6.0,7.0)" />
<PackageVersion Include="StyleCop.Analyzers" Version="[1.2.0-beta.507,2.0)" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="[6.4.0]" />
<PackageVersion Include="Testcontainers.MsSql" Version="3.3.0" />
<PackageVersion Include="Testcontainers.SqlEdge" Version="3.3.0" />
<PackageVersion Include="xunit" Version="[2.5.0,3.0)" />
<PackageVersion Include="xunit.runner.visualstudio" Version="[2.5.0,3.0)" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="[6.5.0,)" />
<PackageVersion Include="Testcontainers.MsSql" Version="3.6.0" />
<PackageVersion Include="Testcontainers.SqlEdge" Version="3.6.0" />
<PackageVersion Include="xunit" Version="[2.6.1,3.0)" />
<PackageVersion Include="xunit.runner.visualstudio" Version="[2.5.3,3.0)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
Expand Down
1 change: 1 addition & 0 deletions OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{7CB2F02E
build\docfx.cmd = build\docfx.cmd
build\docker-compose.net6.0.yml = build\docker-compose.net6.0.yml
build\docker-compose.net7.0.yml = build\docker-compose.net7.0.yml
build\docker-compose.net8.0.yml = build\docker-compose.net8.0.yml
build\finalize-publicapi.ps1 = build\finalize-publicapi.ps1
build\GlobalAttrExclusions.txt = build\GlobalAttrExclusions.txt
build\opentelemetry-icon-color.png = build\opentelemetry-icon-color.png
Expand Down
2 changes: 1 addition & 1 deletion build/Common.nonprod.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<PropertyGroup>
<DefaultTargetFrameworkForExampleApps>net7.0</DefaultTargetFrameworkForExampleApps>
<DefaultTargetFrameworkForExampleApps>net8.0</DefaultTargetFrameworkForExampleApps>
</PropertyGroup>

<PropertyGroup Condition="$(MSBuildProjectName.EndsWith('.Tests'))">
Expand Down
4 changes: 2 additions & 2 deletions examples/MicroserviceExample/WebApi/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG SDK_VERSION=7.0
ARG SDK_VERSION=8.0
FROM mcr.microsoft.com/dotnet/sdk:${SDK_VERSION} AS build
ARG PUBLISH_CONFIGURATION=Release
ARG PUBLISH_FRAMEWORK=net7.0
ARG PUBLISH_FRAMEWORK=net8.0
WORKDIR /app
COPY . ./
RUN dotnet publish ./examples/MicroserviceExample/WebApi -c "${PUBLISH_CONFIGURATION}" -f "${PUBLISH_FRAMEWORK}" -o /out -p:IntegrationBuild=true
Expand Down
4 changes: 2 additions & 2 deletions examples/MicroserviceExample/WorkerService/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG SDK_VERSION=7.0
ARG SDK_VERSION=8.0
FROM mcr.microsoft.com/dotnet/sdk:${SDK_VERSION} AS build
ARG PUBLISH_CONFIGURATION=Release
ARG PUBLISH_FRAMEWORK=net7.0
ARG PUBLISH_FRAMEWORK=net8.0
WORKDIR /app
COPY . ./
RUN dotnet publish ./examples/MicroserviceExample/WorkerService -c "${PUBLISH_CONFIGURATION}" -f "${PUBLISH_FRAMEWORK}" -o /out -p:IntegrationBuild=true
Expand Down
6 changes: 6 additions & 0 deletions src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
* Fixed `network.protocol.version` attribute values to match the specification.
([#5006](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5006))

* Set `network.protocol.version` value using the protocol version on the
received response. If the request fails without response, then
`network.protocol.version` attribute will not be set on Activity and
`http.client.request.duration` metric.
([#5043](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5043))

## 1.6.0-beta.2

Released 2023-Oct-26
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ public void OnStartActivity(Activity activity, object payload)
}

activity.SetTag(SemanticConventions.AttributeUrlFull, HttpTagHelper.GetUriTagValueFromRequestUri(request.RequestUri));
activity.SetTag(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(request.Version));

if (request.Headers.TryGetValues("User-Agent", out var userAgentValues))
{
Expand Down Expand Up @@ -283,6 +282,7 @@ public void OnStopActivity(Activity activity, object payload)

if (this.emitNewAttributes)
{
activity.SetTag(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(response.Version));
activity.SetTag(SemanticConventions.AttributeHttpResponseStatusCode, TelemetryHelper.GetBoxedStatusCode(response.StatusCode));
if (activity.Status == ActivityStatusCode.Error)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public void OnStopEventWritten(Activity activity, object payload)

tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeServerAddress, request.RequestUri.Host));
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeUrlScheme, request.RequestUri.Scheme));
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(request.Version)));

if (!request.RequestUri.IsDefaultPort)
{
Expand All @@ -139,6 +138,7 @@ public void OnStopEventWritten(Activity activity, object payload)

if (TryFetchResponse(payload, out HttpResponseMessage response))
{
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(response.Version)));
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeHttpResponseStatusCode, TelemetryHelper.GetBoxedStatusCode(response.StatusCode)));

// Set error.type to status code for failed requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ private static void AddRequestTagsAndInstrumentRequest(HttpWebRequest request, A
}

activity.SetTag(SemanticConventions.AttributeUrlFull, HttpTagHelper.GetUriTagValueFromRequestUri(request.RequestUri));
activity.SetTag(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(request.ProtocolVersion));
}

try
Expand Down Expand Up @@ -201,6 +200,7 @@ private static void AddResponseTags(HttpWebResponse response, Activity activity)

if (tracingEmitNewAttributes)
{
activity.SetTag(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(response.ProtocolVersion));
activity.SetTag(SemanticConventions.AttributeHttpResponseStatusCode, TelemetryHelper.GetBoxedStatusCode(response.StatusCode));
}

Expand Down Expand Up @@ -243,11 +243,12 @@ private static string GetErrorType(Exception exception)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void AddExceptionTags(Exception exception, Activity activity, out HttpStatusCode? statusCode)
private static void AddExceptionTags(Exception exception, Activity activity, out HttpStatusCode? statusCode, out Version protocolVersion)
{
Debug.Assert(activity != null, "Activity must not be null");

statusCode = null;
protocolVersion = null;

if (!activity.IsAllDataRequested)
{
Expand All @@ -259,6 +260,7 @@ private static void AddExceptionTags(Exception exception, Activity activity, out
if (exception is WebException wexc && wexc.Response is HttpWebResponse response)
{
statusCode = response.StatusCode;
protocolVersion = response.ProtocolVersion;

if (tracingEmitOldAttributes)
{
Expand All @@ -267,6 +269,7 @@ private static void AddExceptionTags(Exception exception, Activity activity, out

if (tracingEmitNewAttributes)
{
activity.SetTag(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(protocolVersion));
activity.SetTag(SemanticConventions.AttributeHttpResponseStatusCode, (int)statusCode);
}

Expand Down Expand Up @@ -397,6 +400,7 @@ private static void ProcessResult(IAsyncResult asyncResult, AsyncCallback asyncC
{
HttpStatusCode? httpStatusCode = null;
string errorType = null;
Version protocolVersion = null;

// Activity may be null if we are not tracing in these cases:
// 1. No listeners
Expand All @@ -415,11 +419,12 @@ private static void ProcessResult(IAsyncResult asyncResult, AsyncCallback asyncC
errorType = GetErrorType(ex);
if (activity != null)
{
AddExceptionTags(ex, activity, out httpStatusCode);
AddExceptionTags(ex, activity, out httpStatusCode, out protocolVersion);
}
else if (ex is WebException wexc && wexc.Response is HttpWebResponse response)
{
httpStatusCode = response.StatusCode;
protocolVersion = response.ProtocolVersion;
}
}
else
Expand Down Expand Up @@ -447,6 +452,7 @@ private static void ProcessResult(IAsyncResult asyncResult, AsyncCallback asyncC
}

httpStatusCode = responseCopy.StatusCode;
protocolVersion = responseCopy.ProtocolVersion;
}
else
{
Expand All @@ -456,6 +462,7 @@ private static void ProcessResult(IAsyncResult asyncResult, AsyncCallback asyncC
}

httpStatusCode = response.StatusCode;
protocolVersion = response.ProtocolVersion;
}

if (SpanHelper.ResolveSpanStatusForHttpStatusCode(ActivityKind.Client, (int)httpStatusCode.Value) == ActivityStatusCode.Error)
Expand Down Expand Up @@ -531,7 +538,11 @@ private static void ProcessResult(IAsyncResult asyncResult, AsyncCallback asyncC

tags.Add(SemanticConventions.AttributeServerAddress, request.RequestUri.Host);
tags.Add(SemanticConventions.AttributeUrlScheme, request.RequestUri.Scheme);
tags.Add(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(request.ProtocolVersion));
if (protocolVersion != null)
{
tags.Add(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetProtocolVersionString(protocolVersion));
}

if (!request.RequestUri.IsDefaultPort)
{
tags.Add(SemanticConventions.AttributeServerPort, request.RequestUri.Port);
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Metrics/Metric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public sealed class Metric
("OpenTelemetry.Instrumentation.Http", "http.client.request.duration"),
("System.Net.Http", "http.client.request.duration"),
("System.Net.Http", "http.client.request.time_in_queue"),
("System.Net.NameResolution", "dns.lookups.duration"),
("System.Net.NameResolution", "dns.lookup.duration"),
};

// Long default histogram bounds. Not based on a standard. May change in the future.
Expand Down
4 changes: 2 additions & 2 deletions test/Benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
Navigate to `./test/Benchmarks` directory and run the following command:

```sh
dotnet run -c Release -f net7.0 -- -m
dotnet run -c Release -f net8.0 -- -m
```

[How to use console arguments](https://benchmarkdotnet.org/articles/guides/console-args.html)

- `-m` enables MemoryDiagnoser and prints memory statistics
- `-f` allows you to filter the benchmarks by their full name using glob patterns
- `dotnet run -c Release -f net7.0 -- -f *TraceBenchmarks*`
- `dotnet run -c Release -f net8.0 -- -f *TraceBenchmarks*`
2 changes: 1 addition & 1 deletion test/OpenTelemetry.Api.Tests/BaggageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public async Task AsyncLocalTests()
{
Baggage.SetBaggage("key1", "value1");

await InnerTask().ConfigureAwait(false);
await InnerTask();

Baggage.SetBaggage("key4", "value4");

Expand Down
6 changes: 3 additions & 3 deletions test/OpenTelemetry.Api.Tests/Trace/TracerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ public async Task Tracer_StartRootSpan_StartsNewTrace()

async Task DoSomeAsyncWork()
{
await Task.Delay(10).ConfigureAwait(false);
await Task.Delay(10);
using (tracer.GetTracer("tracername").StartRootSpan("RootSpan2"))
{
await Task.Delay(10).ConfigureAwait(false);
await Task.Delay(10);
}
}

using (tracer.GetTracer("tracername").StartActiveSpan("RootSpan1"))
{
await DoSomeAsyncWork().ConfigureAwait(false);
await DoSomeAsyncWork();
}

Assert.Equal(2, exportedItems.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ public void SendExportRequest_ExportTraceServiceRequest_SendsCorrectHttpRequest(
{
return new HttpResponseMessage();
})
.Callback<HttpRequestMessage, CancellationToken>((r, ct) =>
.Callback<HttpRequestMessage, CancellationToken>(async (r, ct) =>
{
httpRequest = r;

// We have to capture content as it can't be accessed after request is disposed inside of SendExportRequest method
httpRequestContent = r.Content.ReadAsByteArrayAsync(ct)?.Result;
httpRequestContent = await r.Content.ReadAsByteArrayAsync(ct);
})
#else
.Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
Expand All @@ -124,7 +124,7 @@ public void SendExportRequest_ExportTraceServiceRequest_SendsCorrectHttpRequest(
httpRequest = r;

// We have to capture content as it can't be accessed after request is disposed inside of SendExportRequest method
httpRequestContent = await r.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
httpRequestContent = await r.Content.ReadAsByteArrayAsync();
})
#endif
.Verifiable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public async Task TestRecoveryAfterFailedExport()
endpoints.MapGrpcService<MockTraceService>();
});
}))
.StartAsync().ConfigureAwait(false);
.StartAsync();

var httpClient = new HttpClient() { BaseAddress = new Uri("http://localhost:5050") };

var codes = new[] { Grpc.Core.StatusCode.Unimplemented, Grpc.Core.StatusCode.OK };
await httpClient.GetAsync($"/MockCollector/SetResponseCodes/{string.Join(",", codes.Select(x => (int)x))}").ConfigureAwait(false);
await httpClient.GetAsync($"/MockCollector/SetResponseCodes/{string.Join(",", codes.Select(x => (int)x))}");

var exportResults = new List<ExportResult>();
var otlpExporter = new OtlpTraceExporter(new OtlpExporterOptions() { Endpoint = new Uri("http://localhost:4317") });
Expand Down Expand Up @@ -101,7 +101,7 @@ public async Task TestRecoveryAfterFailedExport()
Assert.Equal(2, exportResults.Count);
Assert.Equal(ExportResult.Success, exportResults[1]);

await host.StopAsync().ConfigureAwait(false);
await host.StopAsync();
}

private class MockCollectorState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ await RunPrometheusExporterMiddlewareIntegrationTest(
path: null,
configureBranchedPipeline: null,
optionsName: null),
registerMeterProvider: false).ConfigureAwait(false);
registerMeterProvider: false);
}

[Fact]
Expand Down Expand Up @@ -235,7 +235,7 @@ await RunPrometheusExporterMiddlewareIntegrationTest(
configureBranchedPipeline: null,
optionsName: null)),
services => services.AddRouting(),
registerMeterProvider: false).ConfigureAwait(false);
registerMeterProvider: false);
}

private static async Task RunPrometheusExporterMiddlewareIntegrationTest(
Expand Down Expand Up @@ -265,7 +265,7 @@ private static async Task RunPrometheusExporterMiddlewareIntegrationTest(
configureServices?.Invoke(services);
})
.Configure(configure))
.StartAsync().ConfigureAwait(false);
.StartAsync();

var tags = new KeyValuePair<string, object>[]
{
Expand All @@ -284,7 +284,7 @@ private static async Task RunPrometheusExporterMiddlewareIntegrationTest(
counter.Add(0.99D, tags);
}

using var response = await host.GetTestClient().GetAsync(path).ConfigureAwait(false);
using var response = await host.GetTestClient().GetAsync(path);

var endTimestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();

Expand All @@ -294,7 +294,7 @@ private static async Task RunPrometheusExporterMiddlewareIntegrationTest(
Assert.True(response.Content.Headers.Contains("Last-Modified"));
Assert.Equal("text/plain; charset=utf-8; version=0.0.4", response.Content.Headers.ContentType.ToString());

string content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
string content = await response.Content.ReadAsStringAsync();

var matches = Regex.Matches(
content,
Expand All @@ -318,7 +318,7 @@ private static async Task RunPrometheusExporterMiddlewareIntegrationTest(

validateResponse?.Invoke(response);

await host.StopAsync().ConfigureAwait(false);
await host.StopAsync();
}
}
#endif
Loading

0 comments on commit 91424a9

Please sign in to comment.