Skip to content

Commit 83a4125

Browse files
committed
Add current state of sub pages
1 parent dc919c0 commit 83a4125

File tree

5 files changed

+385
-9
lines changed

5 files changed

+385
-9
lines changed

develop-docs/sdk/telemetry/spans/index.mdx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,4 @@ title: Spans
33
sidebar_order: 8
44
---
55

6-
This section covers how SDKs should implement a spans-only API to support Sentry's tracing product.
7-
8-
Span API
9-
Span Properties
10-
Span Sampling
11-
Span Protocol
12-
13-
Scopes
6+
<PageGrid />

develop-docs/sdk/telemetry/spans/span-api.mdx

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,182 @@
22
title: Span API
33
---
44

5+
# Span API
56

7+
### `startSpan`
68

9+
Calling the global `startSpan` method always creates a root span.
710

11+
```jsx
12+
span = sentry.tracing.startSpan({
13+
name: 'GET /',
14+
op: 'http.server'
15+
})
16+
```
17+
18+
```jsx
19+
span = sentry().tracing().startSpan()
20+
->setName('GET /')
21+
->setOp('http.server')
22+
```
23+
24+
### `end`
25+
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+
span.end()
43+
```
44+
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+
```
82+
83+
### Start a new root span
84+
85+
Calling the global `startSpan` method always creates a root span.
86+
87+
```jsx
88+
span = sentry.tracing.startSpan({
89+
name: 'GET /',
90+
op: 'http.server',
91+
})
92+
```
93+
94+
```jsx
95+
span = sentry().tracing().startSpan()
96+
->setName('GET /')
97+
->setOp('http.server')
98+
```
99+
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+
```
113+
114+
```jsx
115+
span = sentry().tracing().startSpan()
116+
->setName('GET /')
117+
->setOp('http.server')
118+
->setAtttribute(
119+
key: 'attr1',
120+
value: 'value1',
121+
)
122+
```
123+
124+
### Starting a child span
125+
126+
To create nested spans, you must call `startSpan` on the parent span.
127+
128+
```jsx
129+
span = sentry.tracing.startSpan({ ... })
130+
childSpan = span.startSpan({ ... })
131+
```
132+
133+
```jsx
134+
span = sentry().tracing().startSpan()
135+
childSpan = span.startSpan()
136+
```
137+
138+
### Get the current span
139+
140+
```jsx
141+
span = scope.getSpan()
142+
```
143+
144+
### Set the current span
145+
146+
```jsx
147+
scope.setSpan(span)
148+
```
149+
150+
### Get the root span
151+
152+
```jsx
153+
rootSpan = scope.getRootSpan()
154+
```
155+
156+
### Additional APIs
157+
158+
span.`setStartTimestamp()` - overwrite the span’s start time
159+
160+
span.`setEndTimestamp()` - overwrites the span’s end time
161+
162+
span.`setStatus()` - success, error, unknown
163+
164+
span.`getBaggage()` - returns the baggage string
165+
166+
span.`getTraceparent()` - returns the sentry trace parent string
167+
168+
### Examples
169+
170+
```jsx
171+
rootSpan = sentry.tracing.startSpan({
172+
name: 'GET /',
173+
op: 'http.server',
174+
})
175+
176+
span = rootSpan.startSpan({
177+
name: 'middleware.handle',
178+
op: 'http.middleware',
179+
})
180+
181+
span.end()
182+
rootSpan.end()
183+
```

develop-docs/sdk/telemetry/spans/span-properties.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
title: Span Propertires
33
---
44

5+
# Span Propertires
56

7+
Instead of spans containing tags, context, and data, we'll unify all these properties into a new “attributes” property.
8+
Similar to OTel's semantic conventions, we'll add special meaning to certain attribute keys, such as `sentry.release`, `sentry.op`, etc.
69

10+
```js
11+
span.setAttribute('http.request.method', 'GET')
12+
span.setAttribute('user.email', '[email protected]')
13+
```
714

15+
We'll map these attributes to their respective existing property in Relay to ease the work required for the product during the transition period.

develop-docs/sdk/telemetry/spans/span-protocol.mdx

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,62 @@
22
title: Span Protocol
33
---
44

5+
# Span protocol
56

7+
We'll introduce a new “span” envelope item, which the SDK uses to emit a segment span and its children. And in the future, a batch of spans.
8+
The payload of each envelope item follows the [OpenTelemetry Protocol](https://opentelemetry.io/docs/specs/otel/protocol/), which introduced typed attributes and will ease the conversion in our POtel SDKs.
69

7-
10+
```json
11+
{
12+
"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"
13+
}
14+
{
15+
"type": "span"
16+
}
17+
{
18+
"traceId": "32d3c7cb501fbddbe3ce1016a72d50b5",
19+
"spanId": "e91d37480970523b",
20+
"name": "GET /",
21+
"startTime": "1544712660",
22+
"endTime": "1544712680",
23+
"attributes": [
24+
{
25+
"key": "sentry.op",
26+
"value": {
27+
"stringValue": "http.sever",
28+
}
29+
},
30+
{
31+
"key": "http.response.status_code",
32+
"value": {
33+
"intValue": "200",
34+
}
35+
}
36+
}
37+
}
38+
{
39+
"type": "span"
40+
}
41+
{
42+
"traceId": "32d3c7cb501fbddbe3ce1016a72d50b5",
43+
"spanId": "6b22b3af586e777a",
44+
"parentSpanId": "e91d37480970523b",
45+
"name": "UserMiddleware",
46+
"startTimeUnix": "1544712665",
47+
"endTimeUnix": "1544712675",
48+
"attributes": [
49+
{
50+
"key": "sentry.op",
51+
"value": {
52+
"stringValue": "middleware.handle",
53+
}
54+
},
55+
{
56+
"key": "user.email",
57+
"value": {
58+
"stringValue": "[email protected]",
59+
}
60+
}
61+
}
62+
}
63+
```

0 commit comments

Comments
 (0)