|
1 | 1 | using Sentry.Extensibility; |
2 | 2 | using Sentry.Infrastructure; |
| 3 | +using Sentry.Internal; |
3 | 4 | using Sentry.Protocol; |
4 | 5 |
|
5 | 6 | namespace Sentry; |
6 | 7 |
|
7 | 8 | /// <summary> |
8 | | -/// Represents the Sentry Log protocol. |
| 9 | +/// Represents a Sentry Structured Log. |
9 | 10 | /// <para>This API is experimental and it may change in the future.</para> |
10 | 11 | /// </summary> |
| 12 | +/// <remarks> |
| 13 | +/// Sentry Docs: <see href="https://docs.sentry.io/product/explore/logs/"/>. |
| 14 | +/// Sentry Developer Documentation: <see href="https://develop.sentry.dev/sdk/telemetry/logs/"/>. |
| 15 | +/// Sentry .NET SDK Docs: <see href="https://docs.sentry.io/platforms/dotnet/logs/"/>. |
| 16 | +/// </remarks> |
11 | 17 | [Experimental(DiagnosticId.ExperimentalFeature)] |
12 | 18 | [DebuggerDisplay(@"SentryLog \{ Level = {Level}, Message = '{Message}' \}")] |
13 | 19 | public sealed class SentryLog |
@@ -260,23 +266,26 @@ internal void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger) |
260 | 266 |
|
261 | 267 | internal static void GetTraceIdAndSpanId(IHub hub, out SentryId traceId, out SpanId? spanId) |
262 | 268 | { |
263 | | - var span = hub.GetSpan(); |
264 | | - if (span is not null) |
| 269 | + var activeSpan = hub.GetSpan(); |
| 270 | + if (activeSpan is not null) |
265 | 271 | { |
266 | | - traceId = span.TraceId; |
267 | | - spanId = span.SpanId; |
| 272 | + traceId = activeSpan.TraceId; |
| 273 | + spanId = activeSpan.SpanId; |
268 | 274 | return; |
269 | 275 | } |
270 | 276 |
|
| 277 | + // set "sentry.trace.parent_span_id" to the ID of the Span that was active when the Log was collected |
| 278 | + // do not set "sentry.trace.parent_span_id" if there was no active Span |
| 279 | + spanId = null; |
| 280 | + |
271 | 281 | var scope = hub.GetScope(); |
272 | 282 | if (scope is not null) |
273 | 283 | { |
274 | 284 | traceId = scope.PropagationContext.TraceId; |
275 | | - spanId = scope.PropagationContext.SpanId; |
276 | 285 | return; |
277 | 286 | } |
278 | 287 |
|
| 288 | + Debug.Assert(hub is not Hub, "In case of a 'full' Hub, there is always a Scope. Otherwise (disabled) there is no Scope, but this branch should be unreachable."); |
279 | 289 | traceId = SentryId.Empty; |
280 | | - spanId = null; |
281 | 290 | } |
282 | 291 | } |
0 commit comments