-
-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathSentryOptionsExtensions.cs
More file actions
67 lines (64 loc) · 3.39 KB
/
Copy pathSentryOptionsExtensions.cs
File metadata and controls
67 lines (64 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Trace;
using Sentry.OpenTelemetry.Exporter;
namespace Sentry;
/// <summary>
/// OpenTelemetry Extensions for <see cref="SentryOptions"/>.
/// </summary>
public static class SentryOptionsExtensions
{
/// <summary>
/// <para>Configures Sentry to use OpenTelemetry for distributed tracing. Sentry-instrumented traces will be
/// disabled (so all tracing instrumentation must be done using the OpenTelemetry <see cref="Activity"/> classes).
/// </para>
/// <para>
/// This is the recommended way to set up Sentry's OpenTelemetry integration.
/// </para>
/// </summary>
/// <param name="options">The <see cref="SentryOptions"/> instance.</param>
/// <param name="tracerProviderBuilder"><see cref="TracerProviderBuilder"/></param>
/// <param name="collectorUrl">A custom endpoint to export OLTP trace information to. If no url is provided, the
/// endpoint will be inferred automatically from the DSN.</param>
/// <param name="defaultTextMapPropagator">
/// <para>The default TextMapPropagator to be used by OpenTelemetry.</para>
/// <para>
/// If this parameter is not supplied, a <see cref="CompositeTextMapPropagator"/> containing both
/// W3C <c>traceparent</c>/<c>tracestate</c> and
/// <see cref="OpenTelemetry.SentryPropagator"/> (<c>sentry-trace</c> and <c>baggage</c>) will be used.
/// This allows Sentry to interoperate with services that use W3C trace context headers.
/// </para>
/// <para>
/// The <see cref="OpenTelemetry.SentryPropagator"/> is required for Sentry's OpenTelemetry integration to work. Supply
/// a custom propagator only if you need to replace the defaults entirely.
/// </para>
/// </param>
public static void UseOtlp(this SentryOptions options, TracerProviderBuilder tracerProviderBuilder, Uri? collectorUrl = null, TextMapPropagator? defaultTextMapPropagator = null)
{
if (string.IsNullOrWhiteSpace(options.Dsn))
{
throw new ArgumentException("Sentry DSN must be set before calling `SentryOptions.UseOtlp`", nameof(options.Dsn));
}
tracerProviderBuilder.AddSentryOtlpExporter(options.Dsn, collectorUrl, defaultTextMapPropagator);
options.UseOtlp();
}
/// <summary>
/// <para>Configures Sentry to use OpenTelemetry for distributed tracing. Sentry-instrumented traces will be
/// disabled (so all tracing instrumentation must be done using the OpenTelemetry <see cref="Activity"/> classes).
/// </para>
/// <para>
/// This is the recommended way to set up Sentry's OpenTelemetry integration.
/// </para>
/// </summary>
/// <remarks>
/// Note: if you are using this overload to configure Sentry to work with OpenTelemetry, you will also have to call
/// <see cref="SentryTracerProviderBuilderExtensions.AddSentryOtlpExporter"/>, when building your <see cref="TracerProviderBuilder"/>
/// to ensure OpenTelemetry sends trace information to Sentry.
/// </remarks>
/// <param name="options">The <see cref="SentryOptions"/> instance.</param>
public static void UseOtlp(this SentryOptions options)
{
options.Instrumenter = Instrumenter.OpenTelemetry;
options.DisableSentryTracing = true;
options.ExternalPropagationContext = new OtelPropagationContext();
}
}