@@ -12,74 +12,73 @@ namespace Sentry.OpenTelemetry;
1212/// </summary>
1313public 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