-
-
Notifications
You must be signed in to change notification settings - Fork 223
/
sentry_trace_context.dart
90 lines (76 loc) · 2.54 KB
/
sentry_trace_context.dart
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import 'package:meta/meta.dart';
import '../protocol.dart';
@immutable
class SentryTraceContext {
static const String type = 'trace';
/// Determines which trace the Span belongs to
late final SentryId traceId;
/// Span id
late final SpanId spanId;
/// Id of a parent span
final SpanId? parentSpanId;
/// Whether the span is sampled or not
final bool? sampled;
/// Short code identifying the type of operation the span is measuring
final String operation;
/// Longer description of the span's operation, which uniquely identifies the span but is
/// consistent across instances of the span.
final String? description;
/// The Span status
final SpanStatus? status;
/// The origin of the span indicates what created the span.
///
/// @note Gets set by the SDK. It is not expected to be set manually by users.
///
/// @see <https://develop.sentry.dev/sdk/performance/trace-origin>
final String? origin;
factory SentryTraceContext.fromJson(Map<String, dynamic> json) {
return SentryTraceContext(
operation: json['op'] as String,
spanId: SpanId.fromId(json['span_id'] as String),
parentSpanId: json['parent_span_id'] == null
? null
: SpanId.fromId(json['parent_span_id'] as String),
traceId: SentryId.fromId(json['trace_id'] as String),
description: json['description'] as String?,
status: json['status'] == null
? null
: SpanStatus.fromString(json['status'] as String),
sampled: true,
origin: json['origin'] == null ? null : json['origin'] as String?,
);
}
/// Item encoded as JSON
Map<String, dynamic> toJson() {
return {
'span_id': spanId.toString(),
'trace_id': traceId.toString(),
'op': operation,
if (parentSpanId != null) 'parent_span_id': parentSpanId!.toString(),
if (description != null) 'description': description,
if (status != null) 'status': status!.toString(),
if (origin != null) 'origin': origin,
};
}
SentryTraceContext clone() => SentryTraceContext(
operation: operation,
traceId: traceId,
spanId: spanId,
description: description,
status: status,
parentSpanId: parentSpanId,
sampled: sampled,
origin: origin,
);
SentryTraceContext({
SentryId? traceId,
SpanId? spanId,
this.parentSpanId,
this.sampled,
required this.operation,
this.description,
this.status,
this.origin,
}) : traceId = traceId ?? SentryId.newId(),
spanId = spanId ?? SpanId.newId();
}