You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Spans are measuring the duration of certain operations in an application.
8
+
The topmost member of a span tree is called the root span. This span has no parent span and groups together its children with a representative name for the entire operation, such as `GET /` in case of a request to a backend application.
8
9
9
-
Calling the global `startSpan` method always creates a root span.
10
+
### Creating a root span
10
11
11
-
```jsx
12
-
span =sentry.tracing.startSpan({
13
-
name:'GET /',
14
-
op:'http.server'
15
-
})
16
-
```
12
+
The SDK must expose a method for creating a root span. The user must be able to set certain properties on this root span, such as its name, the type of operation (`op`) and others.
17
13
18
-
```jsx
19
-
span =sentry().tracing().startSpan()
14
+
```js
15
+
span =sentry.tracing.startSpan()
20
16
->setName('GET /')
21
17
->setOp('http.server')
22
-
```
23
-
24
-
### `end`
25
18
26
-
This method sets the end timestamp on the span. If the span is a root span, it emits the entire span tree to Sentry.
27
-
28
-
```jsx
29
-
span =sentry.tracing.startSpan({
30
-
name:'GET /',
31
-
op:'http.server'
32
-
})
33
-
34
-
span.end()
35
-
```
36
-
37
-
```jsx
38
-
span =sentry().tracing().startSpan()
39
-
->setName('GET /')
40
-
->setOp('http.server')
41
-
42
19
span.end()
43
20
```
44
21
45
-
### `continueTraceFrom`
46
-
47
-
Creates a new root span which continues the trace based on the provided trace and parent span id.
48
-
49
-
```jsx
50
-
span =sentry.tracing.startSpan({
51
-
traceId:'',
52
-
parentSpanId:'',
53
-
sampled:true,
54
-
name:'GET /'
55
-
op:'http.server'
56
-
})
57
-
```
58
-
59
-
```jsx
60
-
span =sentry.tracing.startSpan({
61
-
continueTraceFrom: span,
62
-
name:'GET /'
63
-
op:'http.server'
64
-
})
65
-
```
66
-
67
-
```jsx
68
-
span =sentry().tracing().continueTraceFrom({
69
-
traceId:'',
70
-
parentSpanId:'',
71
-
sampled:true,
72
-
})
73
-
->setName('GET /')
74
-
->setOp('http.server')
75
-
```
76
-
77
-
```jsx
78
-
span =sentry().tracing().continueTraceFrom(span)
79
-
->setName('GET /')
80
-
->setOp('http.server')
81
-
```
22
+
### Creating nested spans
82
23
83
-
### Start a new root span
24
+
To create nested spans, the SDK must expose an explicit way for a user to perform this task.
84
25
85
-
Calling the global `startSpan` method always creates a root span.
26
+
Additionally, the SDK may expose alternative APIs to create nested spans, such as allowing a user to wrap an operation into a callback or apply a decorator to certain blocks. These alternative APIs must never create a root span and no-op if no parent span is present.
86
27
87
-
```jsx
88
-
span =sentry.tracing.startSpan({
89
-
name:'GET /',
90
-
op:'http.server',
91
-
})
28
+
```js
29
+
childSpan =span.startChild()
30
+
->setName('authentication middleware')
31
+
->setOp('middleware.handle')
32
+
33
+
childSpan.end()
92
34
```
93
35
94
-
```jsx
95
-
span =sentry().tracing().startSpan()
96
-
->setName('GET /')
97
-
->setOp('http.server')
98
-
```
36
+
### Setting the span status
99
37
100
-
### `setAttribute`
101
-
102
-
```jsx
103
-
span =sentry.tracing.startSpan({
104
-
name:'GET /',
105
-
op:'http.server',
106
-
attributes: {
107
-
attr1:"value1",
108
-
attr2:42,
109
-
attr3:true,
110
-
},
111
-
})
112
-
```
38
+
A span has two statuses, `ok` and `error`. By default, the status of a span is set to `ok`.
39
+
The SDK must allow a user to modify the status of a span.
113
40
114
-
```jsx
115
-
span =sentry().tracing().startSpan()
116
-
->setName('GET /')
117
-
->setOp('http.server')
118
-
->setAtttribute(
119
-
key:'attr1',
120
-
value:'value1',
121
-
)
41
+
```js
42
+
span.setStatus('error')
122
43
```
123
44
124
-
### Starting a child span
45
+
### Setting span attributes
125
46
126
-
To create nested spans, you must call `startSpan` on the parent span.
47
+
The SDK must expose a method to allow a user to set data attributes onto a span.
48
+
These attributes should use pre-defined keys whenever possible.
0 commit comments