Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update OpenTelemetry packages #1278

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shared-package.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<NoWarn>$(NoWarn);CS1591;NU5104</NoWarn>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion shared-test.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<NoWarn>$(NoWarn);S2094</NoWarn>
<NoWarn>$(NoWarn);S2094;NU5104</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 0 additions & 5 deletions src/Common/src/Abstractions/ITracingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ public interface ITracingOptions
/// </remarks>
bool SingleB3Header { get; }

/// <summary>
/// Gets a value indicating whether GRPC requests should participate in tracing.
/// </summary>
bool EnableGrpcAspNetCoreSupport { get; }

/// <summary>
/// Gets a value representing the endpoint used for exporting traces.
/// </summary>
Expand Down
3 changes: 0 additions & 3 deletions src/Common/src/Common/TracingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ public class TracingOptions : ITracingOptions
/// <inheritdoc />
public bool SingleB3Header { get; set; } = true;

/// <inheritdoc />
public bool EnableGrpcAspNetCoreSupport { get; set; } = true;

/// <inheritdoc />
public Uri ExporterEndpoint { get; set; }

Expand Down
6 changes: 3 additions & 3 deletions src/Management/src/Tracing/Steeltoe.Management.Tracing.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<Description>Enables request tracing in distributed systems.</Description>
Expand All @@ -16,8 +16,8 @@
<ItemGroup>
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="$(OpenTelemetryVersion)" />
<PackageReference Include="OpenTelemetry.Extensions.Propagators" Version="$(OpenTelemetryVersion)" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="$(OpenTelemetryInstrumentationVersion)" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="$(OpenTelemetryInstrumentationVersion)" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="$(OpenTelemetryVersion)" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="$(OpenTelemetryVersion)" />
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="$(OpenTelemetryVersion)" PrivateAssets="all" />
<PackageReference Include="OpenTelemetry.Exporter.Jaeger" Version="$(OpenTelemetryExporterJaegerVersion)" PrivateAssets="all" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="$(OpenTelemetryVersion)" PrivateAssets="all" />
Expand Down
115 changes: 58 additions & 57 deletions src/Management/src/Tracing/TracingBaseServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OpenTelemetry;
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Exporter;
using OpenTelemetry.Instrumentation.Http;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using Steeltoe.Common;
Expand All @@ -19,6 +19,7 @@
using Steeltoe.Management.Endpoint;
using Steeltoe.Management.Wavefront.Exporters;
using B3Propagator = OpenTelemetry.Extensions.Propagators.B3Propagator;
using Sdk = OpenTelemetry.Sdk;

namespace Steeltoe.Management.Tracing;

Expand Down Expand Up @@ -60,6 +61,8 @@ public static IServiceCollection AddDistributedTracing(this IServiceCollection s
services.TryAddSingleton<ITracingOptions>(serviceProvider =>
new TracingOptions(serviceProvider.GetRequiredService<IApplicationInstanceInfo>(), serviceProvider.GetRequiredService<IConfiguration>()));

services.ConfigureOptionsWithChangeTokenSource<WavefrontExporterOptions, ConfigureWavefrontExporterOptions>();

services.TryAddEnumerable(ServiceDescriptor.Singleton<IDynamicMessageProcessor, TracingLogProcessor>());

bool exportToZipkin = ReflectionHelpers.IsAssemblyLoaded("OpenTelemetry.Exporter.Zipkin");
Expand All @@ -81,69 +84,72 @@ public static IServiceCollection AddDistributedTracing(this IServiceCollection s
ConfigureOpenTelemetryProtocolOptions(services);
}

services.AddOpenTelemetry().WithTracing(builder =>
services.AddOpenTelemetry().WithTracing(tracerProviderBuilder =>
{
(builder as IDeferredTracerProviderBuilder)?.Configure((serviceProvider, deferredBuilder) =>
tracerProviderBuilder.AddHttpClientInstrumentation();

if (exportToZipkin)
{
string appName = serviceProvider.GetRequiredService<IApplicationInstanceInfo>()
.GetApplicationNameInContext(SteeltoeComponent.Management, $"{TracingOptions.ConfigurationPrefix}:name");
AddZipkinExporter(tracerProviderBuilder);
}

var tracingOptions = serviceProvider.GetRequiredService<ITracingOptions>();
if (exportToJaeger)
{
AddJaegerExporter(tracerProviderBuilder);
}

ILogger logger = serviceProvider.GetRequiredService<ILoggerFactory>()
.CreateLogger($"{typeof(TracingBaseServiceCollectionExtensions).Namespace}.Setup");
if (exportToOpenTelemetryProtocol)
{
AddOpenTelemetryProtocolExporter(tracerProviderBuilder);
}

logger.LogTrace("Found Zipkin exporter: {exportToZipkin}. Found Jaeger exporter: {exportToJaeger}. Found OTLP exporter: {exportToOtlp}.",
exportToZipkin, exportToJaeger, exportToOpenTelemetryProtocol);
action?.Invoke(tracerProviderBuilder);
});

deferredBuilder.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(appName));
services.AddOptions<HttpClientTraceInstrumentationOptions>().Configure<IServiceProvider>((options, serviceProvider) =>
{
var tracingOptions = serviceProvider.GetRequiredService<ITracingOptions>();

deferredBuilder.AddHttpClientInstrumentation(options =>
{
var pathMatcher = new Regex(tracingOptions.EgressIgnorePattern);
options.Filter += requestMessage => !pathMatcher.IsMatch(requestMessage.RequestUri?.PathAndQuery ?? string.Empty);
});
var pathMatcher = new Regex(tracingOptions.EgressIgnorePattern);
options.FilterHttpRequestMessage += requestMessage => !pathMatcher.IsMatch(requestMessage.RequestUri?.PathAndQuery ?? string.Empty);
});

if (tracingOptions.PropagationType.Equals("B3", StringComparison.OrdinalIgnoreCase))
{
var propagators = new List<TextMapPropagator>
{
new B3Propagator(tracingOptions.SingleB3Header),
new BaggagePropagator()
};
services.ConfigureOpenTelemetryTracerProvider((serviceProvider, tracerProviderBuilder) =>
{
string appName = serviceProvider.GetRequiredService<IApplicationInstanceInfo>()
.GetApplicationNameInContext(SteeltoeComponent.Management, $"{TracingOptions.ConfigurationPrefix}:name");

Sdk.SetDefaultTextMapPropagator(new CompositeTextMapPropagator(propagators));
}
var tracingOptions = serviceProvider.GetRequiredService<ITracingOptions>();

if (tracingOptions.NeverSample)
{
deferredBuilder.SetSampler(new AlwaysOffSampler());
}
else if (tracingOptions.AlwaysSample)
{
deferredBuilder.SetSampler(new AlwaysOnSampler());
}
});
ILogger logger = serviceProvider.GetRequiredService<ILoggerFactory>()
.CreateLogger($"{typeof(TracingBaseServiceCollectionExtensions).Namespace}.Setup");

if (exportToZipkin)
logger.LogTrace("Found Zipkin exporter: {exportToZipkin}. Found Jaeger exporter: {exportToJaeger}. Found OTLP exporter: {exportToOtlp}.",
exportToZipkin, exportToJaeger, exportToOpenTelemetryProtocol);

tracerProviderBuilder.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(appName));

if (tracingOptions.PropagationType.Equals("B3", StringComparison.OrdinalIgnoreCase))
{
AddZipkinExporter(builder);
var propagators = new List<TextMapPropagator>
{
new B3Propagator(tracingOptions.SingleB3Header),
new BaggagePropagator()
};

Sdk.SetDefaultTextMapPropagator(new CompositeTextMapPropagator(propagators));
}

if (exportToJaeger)
if (tracingOptions.NeverSample)
{
AddJaegerExporter(builder);
tracerProviderBuilder.SetSampler(new AlwaysOffSampler());
}

if (exportToOpenTelemetryProtocol)
else if (tracingOptions.AlwaysSample)
{
AddOpenTelemetryProtocolExporter(builder);
tracerProviderBuilder.SetSampler(new AlwaysOnSampler());
}

services.ConfigureOptionsWithChangeTokenSource<WavefrontExporterOptions, ConfigureWavefrontExporterOptions>();
AddWavefrontExporter(builder);

action?.Invoke(builder);
AddWavefrontExporter(tracerProviderBuilder, serviceProvider);
});

return services;
Expand Down Expand Up @@ -203,20 +209,15 @@ private static void AddOpenTelemetryProtocolExporter(TracerProviderBuilder build
builder.AddOtlpExporter();
}

private static void AddWavefrontExporter(TracerProviderBuilder builder)
private static void AddWavefrontExporter(TracerProviderBuilder tracerProviderBuilder, IServiceProvider serviceProvider)
{
var deferredTracerProviderBuilder = (IDeferredTracerProviderBuilder)builder;
var wavefrontOptions = serviceProvider.GetRequiredService<IOptions<WavefrontExporterOptions>>();

deferredTracerProviderBuilder.Configure((serviceProvider, innerBuilder) =>
// Only add if wavefront is configured
if (!string.IsNullOrEmpty(wavefrontOptions.Value.Uri))
{
var wavefrontOptions = serviceProvider.GetRequiredService<IOptions<WavefrontExporterOptions>>();

// Only add if wavefront is configured
if (!string.IsNullOrEmpty(wavefrontOptions.Value.Uri))
{
var logger = serviceProvider.GetRequiredService<ILogger<WavefrontTraceExporter>>();
innerBuilder.AddWavefrontTraceExporter(wavefrontOptions.Value, logger);
}
});
var logger = serviceProvider.GetRequiredService<ILogger<WavefrontTraceExporter>>();
tracerProviderBuilder.AddWavefrontTraceExporter(wavefrontOptions.Value, logger);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ public static IServiceCollection AddDistributedTracingAspNetCore(this IServiceCo

action += builder => builder.AddAspNetCoreInstrumentation();

services.AddOptions<AspNetCoreInstrumentationOptions>().PostConfigure<ITracingOptions>((options, traceOpts) =>
services.AddOptions<AspNetCoreTraceInstrumentationOptions>().PostConfigure<ITracingOptions>((instrumentationOptions, tracingOptions) =>
{
var pathMatcher = new Regex(traceOpts.IngressIgnorePattern);
options.EnableGrpcAspNetCoreSupport = traceOpts.EnableGrpcAspNetCoreSupport;
options.Filter += context => !pathMatcher.IsMatch(context.Request.Path);
var pathMatcher = new Regex(tracingOptions.IngressIgnorePattern);
instrumentationOptions.Filter += context => !pathMatcher.IsMatch(context.Request.Path);
});

return services.AddDistributedTracing(action);
Expand Down
4 changes: 2 additions & 2 deletions src/Management/src/Wavefront/Exporters/TagExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ internal static class TagExtensions
{
var tags = new Dictionary<string, string?>();

foreach (KeyValuePair<string, object> tag in tagCollection)
foreach (KeyValuePair<string, object?> tag in tagCollection)
{
if (string.IsNullOrEmpty(tag.Key) || string.IsNullOrEmpty(tag.Value.ToString()))
if (string.IsNullOrEmpty(tag.Key) || tag.Value == null || string.IsNullOrEmpty(tag.Value.ToString()))
bart-vmware marked this conversation as resolved.
Show resolved Hide resolved
{
continue;
}
Expand Down
7 changes: 3 additions & 4 deletions versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@
-->
8.0.*
</FoundationalVersion>
<OpenTelemetryExporterJaegerVersion>1.5.*</OpenTelemetryExporterJaegerVersion>
<OpenTelemetryExporterPrometheusVersion>1.4.0-rc.3</OpenTelemetryExporterPrometheusVersion>
<OpenTelemetryInstrumentationVersion>1.0.0-rc9.2</OpenTelemetryInstrumentationVersion>
<OpenTelemetryVersion>1.6.*</OpenTelemetryVersion>
<OpenTelemetryExporterJaegerVersion>1.6.*-*</OpenTelemetryExporterJaegerVersion>
<OpenTelemetryExporterPrometheusVersion>1.8.*-*</OpenTelemetryExporterPrometheusVersion>
<OpenTelemetryVersion>1.8.*</OpenTelemetryVersion>
<SerilogExtensionsLoggingVersion>7.0.*</SerilogExtensionsLoggingVersion>
<SerilogSettingsConfigurationVersion>7.0.*</SerilogSettingsConfigurationVersion>
<SerilogSinksConsoleVersion>4.1.*</SerilogSinksConsoleVersion>
Expand Down
Loading