Skip to content

Commit 08d8711

Browse files
Revert to classic extension methods
1 parent 442fc7d commit 08d8711

File tree

2 files changed

+96
-98
lines changed

2 files changed

+96
-98
lines changed

src/Sentry.OpenTelemetry/SentryOptionsExtensions.cs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,43 @@ namespace Sentry.OpenTelemetry;
88
/// </summary>
99
public static class SentryOptionsExtensions
1010
{
11-
extension(SentryOptions options)
11+
/// <summary>
12+
/// Enables OpenTelemetry instrumentation with Sentry
13+
/// </summary>
14+
/// <param name="options">The <see cref="SentryOptions"/> instance.</param>
15+
/// <param name="builder"><see cref="TracerProviderBuilder"/></param>
16+
/// <param name="textMapPropagator">
17+
/// <para>The default TextMapPropagator to be used by OpenTelemetry.</para>
18+
/// <para>
19+
/// If this parameter is not supplied, the <see cref="SentryPropagator"/> will be used, which propagates the
20+
/// baggage header as well as Sentry trace headers.
21+
/// </para>
22+
/// <para>
23+
/// The <see cref="SentryPropagator"/> is required for Sentry's OpenTelemetry integration to work but you
24+
/// could wrap this in a <see cref="CompositeTextMapPropagator"/> if you needed other propagators as well.
25+
/// </para>
26+
/// </param>
27+
public static void UseOpenTelemetry(this SentryOptions options, TracerProviderBuilder builder, TextMapPropagator? textMapPropagator = null)
1228
{
13-
/// <summary>
14-
/// Enables OpenTelemetry instrumentation with Sentry
15-
/// </summary>
16-
/// <param name="builder"><see cref="TracerProviderBuilder"/></param>
17-
/// <param name="textMapPropagator">
18-
/// <para>The default TextMapPropagator to be used by OpenTelemetry.</para>
19-
/// <para>
20-
/// If this parameter is not supplied, the <see cref="SentryPropagator"/> will be used, which propagates the
21-
/// baggage header as well as Sentry trace headers.
22-
/// </para>
23-
/// <para>
24-
/// The <see cref="SentryPropagator"/> is required for Sentry's OpenTelemetry integration to work but you
25-
/// could wrap this in a <see cref="CompositeTextMapPropagator"/> if you needed other propagators as well.
26-
/// </para>
27-
/// </param>
28-
public void UseOpenTelemetry(TracerProviderBuilder builder, TextMapPropagator? textMapPropagator = null)
29-
{
30-
options.UseOpenTelemetry();
31-
builder.AddSentry(textMapPropagator);
32-
}
29+
options.UseOpenTelemetry();
30+
builder.AddSentry(textMapPropagator);
31+
}
3332

34-
/// <summary>
35-
/// <para>Configures Sentry to use OpenTelemetry for distributed tracing.</para>
36-
/// <para>
37-
/// Note: if you are using this method to configure Sentry to work with OpenTelemetry, you will also have to call
38-
/// <see cref="O:TracerProviderBuilderExtensions.AddSentry"/> when building your <see cref="TracerProviderBuilder"/>
39-
/// to ensure OpenTelemetry sends trace information to Sentry.
40-
/// </para>
41-
/// </summary>
42-
public void UseOpenTelemetry()
43-
{
44-
options.Instrumenter = Instrumenter.OpenTelemetry;
45-
options.PropagationContextFactory = _ => new OtelPropagationContext();
46-
options.AddTransactionProcessor(
47-
new OpenTelemetryTransactionProcessor()
48-
);
49-
}
33+
/// <summary>
34+
/// <para>Configures Sentry to use OpenTelemetry for distributed tracing.</para>
35+
/// <para>
36+
/// Note: if you are using this method to configure Sentry to work with OpenTelemetry, you will also have to call
37+
/// <see cref="O:TracerProviderBuilderExtensions.AddSentry"/> when building your <see cref="TracerProviderBuilder"/>
38+
/// to ensure OpenTelemetry sends trace information to Sentry.
39+
/// </para>
40+
/// </summary>
41+
/// <param name="options">The <see cref="SentryOptions"/> instance.</param>
42+
public static void UseOpenTelemetry(this SentryOptions options)
43+
{
44+
options.Instrumenter = Instrumenter.OpenTelemetry;
45+
options.PropagationContextFactory = _ => new OtelPropagationContext();
46+
options.AddTransactionProcessor(
47+
new OpenTelemetryTransactionProcessor()
48+
);
5049
}
5150
}

src/Sentry.OpenTelemetry/TracerProviderBuilderExtensions.cs

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -12,74 +12,73 @@ namespace Sentry.OpenTelemetry;
1212
/// </summary>
1313
public static class TracerProviderBuilderExtensions
1414
{
15-
extension(TracerProviderBuilder tracerProviderBuilder)
15+
/// <summary>
16+
/// Ensures OpenTelemetry trace information is sent to Sentry.
17+
/// </summary>
18+
/// <param name="tracerProviderBuilder">The <see cref="TracerProviderBuilder"/>.</param>
19+
/// <param name="defaultTextMapPropagator">
20+
/// <para>The default TextMapPropagator to be used by OpenTelemetry.</para>
21+
/// <para>
22+
/// If this parameter is not supplied, the <see cref="SentryPropagator"/> will be used, which propagates the
23+
/// baggage header as well as Sentry trace headers.
24+
/// </para>
25+
/// <para>
26+
/// The <see cref="SentryPropagator"/> is required for Sentry's OpenTelemetry integration to work but you
27+
/// could wrap this in a <see cref="CompositeTextMapPropagator"/> if you needed other propagators as well.
28+
/// </para>
29+
/// </param>
30+
/// <returns>The supplied <see cref="TracerProviderBuilder"/> for chaining.</returns>
31+
public static TracerProviderBuilder AddSentry(this TracerProviderBuilder tracerProviderBuilder, TextMapPropagator? defaultTextMapPropagator = null)
1632
{
17-
/// <summary>
18-
/// Ensures OpenTelemetry trace information is sent to Sentry.
19-
/// </summary>
20-
/// <param name="defaultTextMapPropagator">
21-
/// <para>The default TextMapPropagator to be used by OpenTelemetry.</para>
22-
/// <para>
23-
/// If this parameter is not supplied, the <see cref="SentryPropagator"/> will be used, which propagates the
24-
/// baggage header as well as Sentry trace headers.
25-
/// </para>
26-
/// <para>
27-
/// The <see cref="SentryPropagator"/> is required for Sentry's OpenTelemetry integration to work but you
28-
/// could wrap this in a <see cref="CompositeTextMapPropagator"/> if you needed other propagators as well.
29-
/// </para>
30-
/// </param>
31-
/// <returns>The supplied <see cref="TracerProviderBuilder"/> for chaining.</returns>
32-
public TracerProviderBuilder AddSentry(TextMapPropagator? defaultTextMapPropagator = null)
33-
{
34-
defaultTextMapPropagator ??= new SentryPropagator();
35-
Sdk.SetDefaultTextMapPropagator(defaultTextMapPropagator);
36-
return tracerProviderBuilder.AddProcessor(ImplementationFactory);
37-
}
33+
defaultTextMapPropagator ??= new SentryPropagator();
34+
Sdk.SetDefaultTextMapPropagator(defaultTextMapPropagator);
35+
return tracerProviderBuilder.AddProcessor(ImplementationFactory);
36+
}
3837

39-
/// <summary>
40-
/// Ensures OpenTelemetry trace information is sent to the Sentry OTLP endpoint.
41-
/// </summary>
42-
/// <param name="dsnString">The DSN for your Sentry project</param>
43-
/// <param name="defaultTextMapPropagator">
44-
/// <para>The default TextMapPropagator to be used by OpenTelemetry.</para>
45-
/// <para>
46-
/// If this parameter is not supplied, the <see cref="SentryPropagator"/> will be used, which propagates the
47-
/// baggage header as well as Sentry trace headers.
48-
/// </para>
49-
/// <para>
50-
/// The <see cref="SentryPropagator"/> is required for Sentry's OpenTelemetry integration to work but you
51-
/// could wrap this in a <see cref="CompositeTextMapPropagator"/> if you needed other propagators as well.
52-
/// </para>
53-
/// </param>
54-
/// <returns>The supplied <see cref="TracerProviderBuilder"/> for chaining.</returns>
55-
public TracerProviderBuilder AddSentry(string dsnString, TextMapPropagator? defaultTextMapPropagator = null)
38+
/// <summary>
39+
/// Ensures OpenTelemetry trace information is sent to the Sentry OTLP endpoint.
40+
/// </summary>
41+
/// <param name="tracerProviderBuilder">The <see cref="TracerProviderBuilder"/>.</param>
42+
/// <param name="dsnString">The DSN for your Sentry project</param>
43+
/// <param name="defaultTextMapPropagator">
44+
/// <para>The default TextMapPropagator to be used by OpenTelemetry.</para>
45+
/// <para>
46+
/// If this parameter is not supplied, the <see cref="SentryPropagator"/> will be used, which propagates the
47+
/// baggage header as well as Sentry trace headers.
48+
/// </para>
49+
/// <para>
50+
/// The <see cref="SentryPropagator"/> is required for Sentry's OpenTelemetry integration to work but you
51+
/// could wrap this in a <see cref="CompositeTextMapPropagator"/> if you needed other propagators as well.
52+
/// </para>
53+
/// </param>
54+
/// <returns>The supplied <see cref="TracerProviderBuilder"/> for chaining.</returns>
55+
public static TracerProviderBuilder AddSentry(this TracerProviderBuilder tracerProviderBuilder, string dsnString, TextMapPropagator? defaultTextMapPropagator = null)
56+
{
57+
if (string.IsNullOrWhiteSpace(dsnString))
5658
{
57-
if (string.IsNullOrWhiteSpace(dsnString))
58-
{
59-
throw new ArgumentException("OTLP endpoint must be provided", nameof(dsnString));
60-
}
59+
throw new ArgumentException("OTLP endpoint must be provided", nameof(dsnString));
60+
}
6161

62-
defaultTextMapPropagator ??= new SentryPropagator();
63-
Sdk.SetDefaultTextMapPropagator(defaultTextMapPropagator);
62+
defaultTextMapPropagator ??= new SentryPropagator();
63+
Sdk.SetDefaultTextMapPropagator(defaultTextMapPropagator);
6464

65-
if (Dsn.TryParse(dsnString) is not { } dsn)
66-
{
67-
return tracerProviderBuilder;
68-
}
65+
if (Dsn.TryParse(dsnString) is not { } dsn)
66+
{
67+
return tracerProviderBuilder;
68+
}
6969

70-
tracerProviderBuilder.AddOtlpExporter(options =>
70+
tracerProviderBuilder.AddOtlpExporter(options =>
71+
{
72+
options.Endpoint = dsn.GetOtlpTracesEndpointUri();
73+
options.Protocol = OtlpExportProtocol.HttpProtobuf;
74+
options.HttpClientFactory = () =>
7175
{
72-
options.Endpoint = dsn.GetOtlpTracesEndpointUri();
73-
options.Protocol = OtlpExportProtocol.HttpProtobuf;
74-
options.HttpClientFactory = () =>
75-
{
76-
var client = new HttpClient();
77-
client.DefaultRequestHeaders.Add("X-Sentry-Auth", $"sentry sentry_key={dsn.PublicKey}");
78-
return client;
79-
};
80-
});
81-
return tracerProviderBuilder.AddProcessor(ImplementationFactory);
82-
}
76+
var client = new HttpClient();
77+
client.DefaultRequestHeaders.Add("X-Sentry-Auth", $"sentry sentry_key={dsn.PublicKey}");
78+
return client;
79+
};
80+
});
81+
return tracerProviderBuilder.AddProcessor(ImplementationFactory);
8382
}
8483

8584
internal static BaseProcessor<Activity> ImplementationFactory(IServiceProvider services)

0 commit comments

Comments
 (0)