forked from getsentry/sentry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpanContext.java
More file actions
134 lines (107 loc) · 3.6 KB
/
SpanContext.java
File metadata and controls
134 lines (107 loc) · 3.6 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package io.sentry;
import com.jakewharton.nopen.annotation.Open;
import io.sentry.protocol.SentryId;
import io.sentry.util.CollectionUtils;
import io.sentry.util.Objects;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
@Open
public class SpanContext implements Cloneable {
public static final String TYPE = "trace";
/** Determines which trace the Span belongs to. */
private final @NotNull SentryId traceId;
/** Span id. */
private final @NotNull SpanId spanId;
/** Id of a parent span. */
private final @Nullable SpanId parentSpanId;
/** If trace is sampled. */
private transient @Nullable Boolean sampled;
/** Short code identifying the type of operation the span is measuring. */
protected @NotNull String op;
/**
* Longer description of the span's operation, which uniquely identifies the span but is
* consistent across instances of the span.
*/
protected @Nullable String description;
/** Describes the status of the Transaction. */
protected @Nullable SpanStatus status;
/** A map or list of tags for this event. Each tag must be less than 200 characters. */
protected @NotNull Map<String, String> tags = new ConcurrentHashMap<>();
public SpanContext(final @NotNull String operation, final @Nullable Boolean sampled) {
this(new SentryId(), new SpanId(), operation, null, sampled);
}
/**
* Creates trace context with defered sampling decision.
*
* @param operation the operation
*/
public SpanContext(final @NotNull String operation) {
this(new SentryId(), new SpanId(), operation, null, null);
}
public SpanContext(
final @NotNull SentryId traceId,
final @NotNull SpanId spanId,
final @NotNull String operation,
final @Nullable SpanId parentSpanId,
final @Nullable Boolean sampled) {
this.traceId = Objects.requireNonNull(traceId, "traceId is required");
this.spanId = Objects.requireNonNull(spanId, "spanId is required");
this.op = Objects.requireNonNull(operation, "operation is required");
this.parentSpanId = parentSpanId;
this.sampled = sampled;
}
public void setOperation(final @NotNull String operation) {
this.op = Objects.requireNonNull(operation, "operation is required");
}
public void setTag(final @NotNull String name, final @NotNull String value) {
Objects.requireNonNull(name, "name is required");
Objects.requireNonNull(value, "value is required");
this.tags.put(name, value);
}
public void setDescription(final @Nullable String description) {
this.description = description;
}
public void setStatus(final @Nullable SpanStatus status) {
this.status = status;
}
@NotNull
public SentryId getTraceId() {
return traceId;
}
@NotNull
public SpanId getSpanId() {
return spanId;
}
@Nullable
@TestOnly
public SpanId getParentSpanId() {
return parentSpanId;
}
public @NotNull String getOperation() {
return op;
}
public @Nullable String getDescription() {
return description;
}
public @Nullable SpanStatus getStatus() {
return status;
}
public @NotNull Map<String, String> getTags() {
return tags;
}
public @Nullable Boolean getSampled() {
return sampled;
}
void setSampled(final @Nullable Boolean sampled) {
this.sampled = sampled;
}
@Override
public SpanContext clone() throws CloneNotSupportedException {
final SpanContext clone = (SpanContext) super.clone();
clone.tags = CollectionUtils.shallowCopy(tags);
return clone;
}
}