Skip to content

Commit 4aa9a7e

Browse files
authored
ref: Amend span creation names for RFC 101 (#113)
1 parent 2ce97d3 commit 4aa9a7e

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

text/0101-revamping-the-sdk-performance-api.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ Note: In a previous version of this RFC there was a focus on updating the span s
1818

1919
# Planned Work
2020

21-
The primary planned work in this RFC is to introduce three new top-level methods, `Sentry.startActiveSpan` and `Sentry.startSpan` and their language-specific variants as well as `Sentry.setMeasurement`.
21+
The primary planned work in this RFC is to introduce three new top-level methods, `Sentry.startSpan` and `Sentry.startInactiveSpan` and their language-specific variants as well as `Sentry.setMeasurement`.
2222

23-
This allows us to de-emphasize the concept of hubs, scopes, and transactions from users, and instead have them think about just spans. Under the hood, `Sentry.startActiveSpan` and `Sentry.startSpan` should create transactions/spans as appropriate. `Sentry.setMeasurement` is used to abstract away `transaction.setMeasurement` and similar.
23+
This allows us to de-emphasize the concept of hubs, scopes, and transactions from users, and instead have them think about just spans. Under the hood, `Sentry.startSpan` and `Sentry.startInactiveSpan` should create transactions/spans as appropriate. `Sentry.setMeasurement` is used to abstract away `transaction.setMeasurement` and similar.
2424

2525
In a previous version of the RFC, there was a follow-up step to update the span schema. This will be focused on later and for now, is not in scope for performance API improvements.
2626

@@ -111,13 +111,13 @@ The new SDK API has the following requirements:
111111
112112
### Span Creators
113113
114-
There are two top-level methods we'll be introducing to achieve this: `Sentry.startActiveSpan` and `Sentry.startSpan`. `Sentry.startActiveSpan` will take a callback and start/stop a span automatically. In addition, it'll also set the span on the current scope. Under the hood, the SDK will create a transaction or span based on if there is already an existing span on the scope.
114+
There are two top-level methods we'll be introducing to achieve this: `Sentry.startSpan` and `Sentry.startInactiveSpan`. `Sentry.startSpan` will take a callback and start/stop a span automatically. In addition, it'll also set the span on the current scope. Under the hood, the SDK will create a transaction or span based on if there is already an existing span on the scope.
115115
116-
The reason for electing to have `startActiveSpan` and `startSpan` as separate top-level methods is to not burden the user with having to know about scope propagation, since the concept of a scope might change in future versions of the unified API. If this is not viable at all for a language or certain frameworks, SDK authors can opt to include the `onScope` parameter to the `startSpan` call that will automatically set the span on the current scope, but this is not recommended.
116+
The reason for electing to have `startSpan` and `startInactiveSpan` as separate top-level methods is to not burden the user with having to know about scope propagation, since the concept of a scope might change in future versions of the unified API. If this is not viable at all for a language or certain frameworks, SDK authors can opt to include the `onScope` parameter to the `startInactiveSpan` call that will automatically set the span on the current scope, but this is not recommended.
117117
118118
```ts
119119
namespace Sentry {
120-
declare function startActiveSpan<T>(
120+
declare function startSpan<T>(
121121
spanContext: SpanContext,
122122
callback: (span: Span) => T
123123
): T;
@@ -126,9 +126,8 @@ namespace Sentry {
126126
// span that is created is provided to callback in case additional
127127
// attributes have to be added.
128128
// ideally callback can be async/sync
129-
const returnVal = Sentry.startActiveSpan(
130-
{ name: "expensiveCalc" },
131-
(span: Span) => expensiveCalc()
129+
const returnVal = Sentry.startSpan({ name: "expensiveCalc" }, (span: Span) =>
130+
expensiveCalc()
132131
);
133132

134133
// If the SDK needs async/sync typed differently it can be exposed as `startActiveSpanAsync`
@@ -138,46 +137,46 @@ const returnVal = Sentry.startActiveSpan(
138137
// ): Promise<T>;
139138
```
140139
141-
In the ideal case, `startActiveSpan` should generally follow this code path.
140+
In the ideal case, `startSpan` should generally follow this code path.
142141
143142
1. Get the active span from the current scope
144143
2. If the active span is defined, create a child span of that active span based on the provided `spanContext`, otherwise create a transaction based on the provided `spanContext`.
145144
3. Run the provided callback
146145
4. Finish the child span/transaction created in Step 2
147146
5. Remove the child span/transaction from the current scope and if it exists, set the previous active span as the active span in the current scope.
148147
149-
If the provided callback throws an exception, the span/transaction created in Step 2 should be marked as errored. This error should not be swallowed by `startActiveSpan`.
148+
If the provided callback throws an exception, the span/transaction created in Step 2 should be marked as errored. This error should not be swallowed by `startSpan`.
150149
151-
`startActiveSpan` only provides the correct parent-child relationship if your platform has proper support for forking scopes. For platforms that have a single hub/scope (like the mobile SDKs), this method will not lead to the correct parent-child relationship. The SDK will have to provide a different method for these platforms. The recommended option here is for `startActiveSpan` to always attach the span it creates to the root span (the transaction), which means users don't get exact parent-child relationships, but they do get relative relationships between spans using relative durations.
150+
`startSpan` only provides the correct parent-child relationship if your platform has proper support for forking scopes. For platforms that have a single hub/scope (like the mobile SDKs), this method will not lead to the correct parent-child relationship. The SDK will have to provide a different method for these platforms. The recommended option here is for `startSpan` to always attach the span it creates to the root span (the transaction), which means users don't get exact parent-child relationships, but they do get relative relationships between spans using relative durations.
152151
153-
`Sentry.startSpan` will create a span, but not set it as the active span in the current scope.
152+
`Sentry.startInactiveSpan` will create a span, but not set it as the active span in the current scope.
154153
155154
```ts
156155
namespace Sentry {
157-
declare function startSpan(spanContext: SpanContext): Span;
156+
declare function startInactiveSpan(spanContext: SpanContext): Span;
158157
}
159158

160159
// does not get put on the scope
161-
const span = Sentry.startSpan({ name: "expensiveCalc" });
160+
const span = Sentry.startInactiveSpan({ name: "expensiveCalc" });
162161

163162
expensiveCalc();
164163

165164
span.finish();
166165
```
167166
168-
The goal here is to make span creation consistent across all SDKs, but we also want to make sure that the SDKs are idiomatic for their language/runtime. SDK authors are free to add additional methods to start spans if they feel that `startActiveSpan` and `startSpan` are not appropriate for their language/framework/runtime.
167+
The goal here is to make span creation consistent across all SDKs, but we also want to make sure that the SDKs are idiomatic for their language/runtime. SDK authors are free to add additional methods to start spans if they feel that `startSpan` and `startInactiveSpan` are not appropriate for their language/framework/runtime.
169168
170169
For example, with go we could have a method that starts a span from a go context:
171170
172171
```go
173172
sentry.StartSpanFromContext(ctx, spanCtx)
174173
```
175174
176-
SDK authors can also change the behaviour of `startActiveSpan` and `startSpan` if they feel that the outlined behaviour is not idiomatic for their language/framework/runtime, but this is not recommended and should be discussed with the greater SDK team before being implemented.
175+
SDK authors can also change the behaviour of `startSpan` and `startInactiveSpan` if they feel that the outlined behaviour is not idiomatic for their language/framework/runtime, but this is not recommended and should be discussed with the greater SDK team before being implemented.
177176
178177
### Span Name
179178
180-
To accommodate the inclusion of `Sentry.startActiveSpan` and `Sentry.startSpan`, the `span.name` field should be used and is an alias for `span.description`. Span name should become required for the span context argument that is accepted by `Sentry.startActiveSpan` and `Sentry.startSpan`.
179+
To accommodate the inclusion of `Sentry.startSpan` and `Sentry.startInactiveSpan`, the `span.name` field should be used and is an alias for `span.description`. Span name should become required for the span context argument that is accepted by `Sentry.startSpan` and `Sentry.startInactiveSpan`.
181180
182181
This means methods for setting a span name should be added to the span interface.
183182

0 commit comments

Comments
 (0)