[WCF] Adjustments for changes in OpenTelemetry.Instrumentation.Wcf 1.0.0-rc.13 (#3070)

This commit is contained in:
Mateusz Łach 2023-11-06 12:28:59 +01:00 committed by GitHub
parent 819320077a
commit 7d93b26cf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 6 deletions

View File

@ -31,6 +31,7 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h
- .NET Framework only, `OpenTelemetry.Instrumentation.AspNet` and
`OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule` updated from
`1.6.0-beta.1` to `1.6.0-beta.2`.
- `OpenTelemetry.Instrumentation.Wcf` updated from `1.0.0-rc.12` to `1.0.0-rc.13`.
### Deprecated

View File

@ -11,6 +11,6 @@
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="1.6.0" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.6.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.6.0-beta.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Wcf" Version="1.0.0-rc.12" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Wcf" Version="1.0.0-rc.13" />
</ItemGroup>
</Project>

View File

@ -119,7 +119,7 @@ public class MyPlugin
| OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions | OpenTelemetry.Instrumentation.Quartz | 1.0.0-alpha.3 |
| OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions | OpenTelemetry.Instrumentation.SqlClient | 1.6.0-beta.2 |
| OpenTelemetry.Instrumentation.StackExchangeRedis.StackExchangeRedisInstrumentationOptions | OpenTelemetry.Instrumentation.StackExchangeRedis | 1.0.0-rc9.12 |
| OpenTelemetry.Instrumentation.Wcf.WcfInstrumentationOptions | OpenTelemetry.Instrumentation.Wcf | 1.0.0-rc.12 |
| OpenTelemetry.Instrumentation.Wcf.WcfInstrumentationOptions | OpenTelemetry.Instrumentation.Wcf | 1.0.0-rc.13 |
### Metrics

View File

@ -52,7 +52,7 @@ void CorProfiler::InitNetFxAssemblyRedirectsMap()
{ L"OpenTelemetry.Instrumentation.Quartz", {1, 0, 0, 3} },
{ L"OpenTelemetry.Instrumentation.Runtime", {1, 5, 1, 0} },
{ L"OpenTelemetry.Instrumentation.SqlClient", {1, 0, 0, 0} },
{ L"OpenTelemetry.Instrumentation.Wcf", {1, 0, 0, 12} },
{ L"OpenTelemetry.Instrumentation.Wcf", {1, 0, 0, 13} },
{ L"OpenTelemetry.ResourceDetectors.Azure", {1, 0, 0, 3} },
{ L"OpenTelemetry.ResourceDetectors.Container", {1, 0, 0, 4} },
{ L"OpenTelemetry.Shims.OpenTracing", {1, 0, 0, 0} },

View File

@ -14,6 +14,8 @@
// limitations under the License.
// </copyright>
using System.Reflection;
using OpenTelemetry.AutoInstrumentation.Configurations;
using OpenTelemetry.AutoInstrumentation.Plugins;
using OpenTelemetry.Instrumentation.Wcf;
@ -42,5 +44,15 @@ internal class WcfInitializer : InstrumentationInitializer
var instrumentationType = Type.GetType("OpenTelemetry.Instrumentation.Wcf.WcfInstrumentationActivitySource, OpenTelemetry.Instrumentation.Wcf");
instrumentationType?.GetProperty("Options")?.SetValue(null, options);
#if NETFRAMEWORK
var enabledTraceInstrumentations = Instrumentation.TracerSettings.Value.EnabledInstrumentations;
if (enabledTraceInstrumentations.Contains(TracerInstrumentation.WcfService) && enabledTraceInstrumentations.Contains(TracerInstrumentation.AspNet))
{
var aspNetParentSpanCorrectorType = Type.GetType("OpenTelemetry.Instrumentation.Wcf.Implementation.AspNetParentSpanCorrector, OpenTelemetry.Instrumentation.Wcf");
var methodInfo = aspNetParentSpanCorrectorType?.GetMethod("Register", BindingFlags.Static | BindingFlags.Public);
methodInfo?.Invoke(null, null);
}
#endif
}
}

View File

@ -18,6 +18,7 @@
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;
using FluentAssertions;
using Google.Protobuf;
using IntegrationTests.Helpers;
using OpenTelemetry.Proto.Trace.V1;
using Xunit.Abstractions;
@ -51,16 +52,18 @@ public class WcfIISTests : TestHelper
var netTcpPort = TcpPortProvider.GetOpenPort();
var httpPort = TcpPortProvider.GetOpenPort();
collector.Expect("OpenTelemetry.Instrumentation.Wcf", span => span.Kind == Span.Types.SpanKind.Server, "Server 1");
collector.Expect("OpenTelemetry.Instrumentation.Wcf", span => span.Kind == Span.Types.SpanKind.Server && !IndicatesHealthCheckRequest(span), "Server 1");
// filtering by name required, because client instrumentation creates some additional spans, e.g for connection registration
collector.Expect("OpenTelemetry.Instrumentation.Wcf", span => span.Kind == Span.Types.SpanKind.Client && span.Name == "http://opentelemetry.io/StatusService/Ping", "Client 1");
collector.Expect("OpenTelemetry.Instrumentation.Wcf", span => span.Kind == Span.Types.SpanKind.Server, "Server 2");
collector.Expect("OpenTelemetry.Instrumentation.Wcf", span => span.Kind == Span.Types.SpanKind.Server && !IndicatesHealthCheckRequest(span), "Server 2");
collector.Expect("OpenTelemetry.Instrumentation.Wcf", span => span.Kind == Span.Types.SpanKind.Client && span.Name == "http://opentelemetry.io/StatusService/Ping", "Client 2");
collector.Expect("OpenTelemetry.Instrumentation.AspNet.Telemetry", span => span.Kind == Span.Types.SpanKind.Server && span.ParentSpanId != ByteString.Empty, "AspNet Server 1");
collector.Expect("TestApplication.Wcf.Client.NetFramework", span => span.Kind == Span.Types.SpanKind.Internal, "Custom parent");
collector.Expect("TestApplication.Wcf.Client.NetFramework", span => span.Kind == Span.Types.SpanKind.Internal, "Custom sibling");
collector.ExpectCollected(WcfClientInstrumentation.ValidateExpectedSpanHierarchy);
collector.ExpectCollected(ValidateExpectedSpanHierarchy);
var collectorUrl = $"http://{DockerNetworkHelper.IntegrationTestsGateway}:{collector.Port}";
_environmentVariables["OTEL_EXPORTER_OTLP_ENDPOINT"] = collectorUrl;
@ -75,6 +78,23 @@ public class WcfIISTests : TestHelper
collector.AssertExpectations();
}
private static bool IndicatesHealthCheckRequest(Span span)
{
return span.Attributes.Single(attr => attr.Key == "rpc.method").Value.StringValue == string.Empty;
}
private static bool ValidateExpectedSpanHierarchy(ICollection<MockSpansCollector.Collected> collectedSpans)
{
var wcfServerSpans = collectedSpans.Where(collected =>
collected.Span.Kind == Span.Types.SpanKind.Server &&
collected.InstrumentationScopeName == "OpenTelemetry.Instrumentation.Wcf");
var aspNetServerSpan = collectedSpans.Single(collected =>
collected.Span.Kind == Span.Types.SpanKind.Server &&
collected.InstrumentationScopeName == "OpenTelemetry.Instrumentation.AspNet.Telemetry");
var aspNetParentedWcfServerSpans = wcfServerSpans.Count(sp => sp.Span.ParentSpanId == aspNetServerSpan.Span.SpanId);
return aspNetParentedWcfServerSpans == 1 && WcfClientInstrumentation.ValidateExpectedSpanHierarchy(collectedSpans);
}
private async Task<IContainer> StartContainerAsync(int netTcpPort, int httpPort)
{
const string imageName = "testapplication-wcf-server-iis-netframework";