@@ -9,7 +9,7 @@ namespace Sentry.OpenTelemetry;
99public static class SentryOptionsExtensions
1010{
1111 /// <summary>
12- /// Enables OpenTelemetry instrumentation with Sentry
12+ /// Configures Sentry to use OpenTelemetry for distributed tracing.
1313 /// </summary>
1414 /// <param name="options">The <see cref="SentryOptions"/> instance.</param>
1515 /// <param name="builder"><see cref="TracerProviderBuilder"/></param>
@@ -24,27 +24,98 @@ public static class SentryOptionsExtensions
2424 /// could wrap this in a <see cref="CompositeTextMapPropagator"/> if you needed other propagators as well.
2525 /// </para>
2626 /// </param>
27- public static void UseOpenTelemetry ( this SentryOptions options , TracerProviderBuilder builder , TextMapPropagator ? textMapPropagator = null )
27+ /// <param name="disableSentryTracing">Whether to disable traces created using Sentry's tracing instrumentation.
28+ /// It's recommended that you set this to <c>true</c> since mixing OpenTelemetry and Sentry traces may yield
29+ /// unexpected results. It is <c>false</c> by default for backward compatibility only.
30+ /// </param>
31+ /// <remarks>
32+ /// This method of initialising the Sentry OpenTelemetry integration will be depricated in a future major release.
33+ /// We recommend you use <see cref="UseOTLP(SentryOptions, TracerProviderBuilder, TextMapPropagator?)"/> instead.
34+ /// </remarks>
35+ public static void UseOpenTelemetry ( this SentryOptions options , TracerProviderBuilder builder ,
36+ TextMapPropagator ? textMapPropagator = null , bool disableSentryTracing = false )
2837 {
29- options . UseOpenTelemetry ( ) ;
38+ options . UseOpenTelemetry ( disableSentryTracing ) ;
3039 builder . AddSentry ( textMapPropagator ) ;
3140 }
3241
3342 /// <summary>
34- /// <para>Configures Sentry to use OpenTelemetry for distributed tracing.</para>
43+ /// <para>Configures Sentry to use OpenTelemetry for distributed tracing.
44+ /// </para>
3545 /// <para>
36- /// Note: if you are using this method to configure Sentry to work with OpenTelemetry, you will also have to call
46+ /// Note: if you are using this overload to configure Sentry to work with OpenTelemetry, you will also have to call
3747 /// <see cref="O:TracerProviderBuilderExtensions.AddSentry"/> when building your <see cref="TracerProviderBuilder"/>
3848 /// to ensure OpenTelemetry sends trace information to Sentry.
3949 /// </para>
4050 /// </summary>
4151 /// <param name="options">The <see cref="SentryOptions"/> instance.</param>
42- public static void UseOpenTelemetry ( this SentryOptions options )
52+ /// <param name="disableSentryTracing">Whether to disable traces created using Sentry's tracing instrumentation.
53+ /// It's recommended that you set this to <c>true</c> since mixing OpenTelemetry and Sentry traces may yield
54+ /// unexpected results. It is <c>false</c> by default for backward compatibility only.
55+ /// </param>
56+ /// <remarks>
57+ /// This method of initialising the Sentry OpenTelemetry integration will be depricated in a future major release.
58+ /// We recommend you use <see cref="UseOTLP(SentryOptions, TracerProviderBuilder, TextMapPropagator?)"/> instead.
59+ /// </remarks>
60+ public static void UseOpenTelemetry ( this SentryOptions options , bool disableSentryTracing = false )
4361 {
4462 options . Instrumenter = Instrumenter . OpenTelemetry ;
63+ options . DisableSentryTracing = disableSentryTracing ;
4564 options . PropagationContextFactory = _ => new OtelPropagationContext ( ) ;
4665 options . AddTransactionProcessor (
4766 new OpenTelemetryTransactionProcessor ( )
4867 ) ;
4968 }
69+
70+ /// <summary>
71+ /// <para>Configures Sentry to use OpenTelemetry for distributed tracing. Sentry instrumented traces will be
72+ /// disabled (so all tracing instrumentation must be done using the OpenTelemetry <see cref="Activity"/> classes).
73+ /// </para>
74+ /// <para>
75+ /// This is the recommended way to set up Sentry's OpenTelemetry integration.
76+ /// </para>
77+ /// </summary>
78+ /// <param name="options">The <see cref="SentryOptions"/> instance.</param>
79+ /// <param name="builder"><see cref="TracerProviderBuilder"/></param>
80+ /// <param name="textMapPropagator">
81+ /// <para>The default TextMapPropagator to be used by OpenTelemetry.</para>
82+ /// <para>
83+ /// If this parameter is not supplied, the <see cref="SentryPropagator"/> will be used, which propagates the
84+ /// baggage header as well as Sentry trace headers.
85+ /// </para>
86+ /// <para>
87+ /// The <see cref="SentryPropagator"/> is required for Sentry's OpenTelemetry integration to work but you
88+ /// could wrap this in a <see cref="CompositeTextMapPropagator"/> if you needed other propagators as well.
89+ /// </para>
90+ /// </param>
91+ public static void UseOTLP ( this SentryOptions options , TracerProviderBuilder builder , TextMapPropagator ? textMapPropagator = null )
92+ {
93+ if ( string . IsNullOrWhiteSpace ( options . Dsn ) )
94+ {
95+ throw new ArgumentException ( "Sentry DSN must be set before calling `SentryOptions.UseOTLP`" , nameof ( options . Dsn ) ) ;
96+ }
97+ builder . AddSentryOTLP ( options . Dsn , textMapPropagator ) ;
98+ options . UseOTLP ( ) ;
99+ }
100+
101+ /// <summary>
102+ /// <para>Configures Sentry to use OpenTelemetry for distributed tracing. Sentry instrumented traces will be
103+ /// disabled (so all tracing instrumentation must be done using the OpenTelemetry <see cref="Activity"/> classes).
104+ /// </para>
105+ /// <para>
106+ /// This is the recommended way to set up Sentry's OpenTelemetry integration.
107+ /// </para>
108+ /// </summary>
109+ /// <remarks>
110+ /// Note: if you are using this overload to configure Sentry to work with OpenTelemetry, you will also have to call
111+ /// <see cref="TracerProviderBuilderExtensions.AddSentryOTLP"/>, when building your <see cref="TracerProviderBuilder"/>
112+ /// to ensure OpenTelemetry sends trace information to Sentry.
113+ /// </remarks>
114+ /// <param name="options">The <see cref="SentryOptions"/> instance.</param>
115+ public static void UseOTLP ( this SentryOptions options )
116+ {
117+ options . Instrumenter = Instrumenter . OpenTelemetry ;
118+ options . DisableSentryTracing = true ;
119+ options . PropagationContextFactory = _ => new OtelPropagationContext ( ) ;
120+ }
50121}
0 commit comments