-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(core): Add options to start standalone (segment) spans via start*Span
APIs
#11696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
67654bc
feat(browser): Start standalone (segment) spans via `start*Span` APIs
Lms24 63ce8c7
cleanup
Lms24 8b3627a
jsdoc
Lms24 922ccf3
reduce to `standalone: boolean`; remove `segment`
Lms24 46182e9
ensure standalone spans are filtered out when transaction is active
Lms24 02b1947
cleanup
Lms24 5731bae
cleanup
Lms24 a218408
change segment_id and is_segment in getSpanJson
Lms24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...rowser-integration-tests/suites/public-api/startSpan/standalone-mixed-transaction/init.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
tracesSampleRate: 1.0, | ||
}); |
4 changes: 4 additions & 0 deletions
4
...ser-integration-tests/suites/public-api/startSpan/standalone-mixed-transaction/subject.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Sentry.startSpan({ name: 'outer' }, () => { | ||
Sentry.startSpan({ name: 'inner' }, () => {}); | ||
Sentry.startSpan({ name: 'standalone', experimental: { standalone: true } }, () => {}); | ||
}); |
122 changes: 122 additions & 0 deletions
122
...rowser-integration-tests/suites/public-api/startSpan/standalone-mixed-transaction/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Envelope, EventEnvelope, SpanEnvelope, TransactionEvent } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { | ||
getMultipleSentryEnvelopeRequests, | ||
properFullEnvelopeRequestParser, | ||
shouldSkipTracingTest, | ||
} from '../../../../utils/helpers'; | ||
|
||
sentryTest( | ||
'sends a transaction and a span envelope if a standalone span is created as a child of an ongoing span tree', | ||
async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
const envelopes = await getMultipleSentryEnvelopeRequests<Envelope>( | ||
page, | ||
2, | ||
{ url, envelopeType: ['transaction', 'span'] }, | ||
properFullEnvelopeRequestParser, | ||
); | ||
|
||
const spanEnvelope = envelopes.find(envelope => envelope[1][0][0].type === 'span') as SpanEnvelope; | ||
const transactionEnvelope = envelopes.find(envelope => envelope[1][0][0].type === 'transaction') as EventEnvelope; | ||
|
||
const spanEnvelopeHeader = spanEnvelope[0]; | ||
const spanEnvelopeItem = spanEnvelope[1][0][1]; | ||
|
||
const transactionEnvelopeHeader = transactionEnvelope[0]; | ||
const transactionEnvelopeItem = transactionEnvelope[1][0][1] as TransactionEvent; | ||
|
||
const traceId = transactionEnvelopeHeader.trace!.trace_id!; | ||
const parentSpanId = transactionEnvelopeItem.contexts?.trace?.span_id; | ||
|
||
expect(traceId).toMatch(/[a-f0-9]{32}/); | ||
expect(parentSpanId).toMatch(/[a-f0-9]{16}/); | ||
|
||
// TODO: the span envelope also needs to contain the `trace` header (follow-up PR) | ||
expect(spanEnvelopeHeader).toEqual({ | ||
sent_at: expect.any(String), | ||
}); | ||
|
||
expect(transactionEnvelopeHeader).toEqual({ | ||
event_id: expect.any(String), | ||
sdk: { | ||
name: 'sentry.javascript.browser', | ||
version: expect.any(String), | ||
}, | ||
sent_at: expect.any(String), | ||
trace: { | ||
environment: 'production', | ||
public_key: 'public', | ||
sample_rate: '1', | ||
sampled: 'true', | ||
trace_id: traceId, | ||
transaction: 'outer', | ||
}, | ||
}); | ||
|
||
expect(spanEnvelopeItem).toEqual({ | ||
data: { | ||
'sentry.origin': 'manual', | ||
}, | ||
description: 'standalone', | ||
segment_id: spanEnvelopeItem.span_id, | ||
is_segment: true, | ||
parent_span_id: parentSpanId, | ||
origin: 'manual', | ||
span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
start_timestamp: expect.any(Number), | ||
timestamp: expect.any(Number), | ||
trace_id: traceId, | ||
}); | ||
|
||
expect(transactionEnvelopeItem).toEqual({ | ||
contexts: { | ||
trace: { | ||
data: { | ||
'sentry.origin': 'manual', | ||
'sentry.sample_rate': 1, | ||
'sentry.source': 'custom', | ||
}, | ||
origin: 'manual', | ||
span_id: parentSpanId, | ||
trace_id: traceId, | ||
}, | ||
}, | ||
environment: 'production', | ||
event_id: expect.any(String), | ||
platform: 'javascript', | ||
request: { | ||
headers: expect.any(Object), | ||
url: expect.any(String), | ||
}, | ||
sdk: expect.any(Object), | ||
spans: [ | ||
{ | ||
data: { | ||
'sentry.origin': 'manual', | ||
}, | ||
description: 'inner', | ||
origin: 'manual', | ||
parent_span_id: parentSpanId, | ||
span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
start_timestamp: expect.any(Number), | ||
timestamp: expect.any(Number), | ||
trace_id: traceId, | ||
}, | ||
], | ||
start_timestamp: expect.any(Number), | ||
timestamp: expect.any(Number), | ||
transaction: 'outer', | ||
transaction_info: { | ||
source: 'custom', | ||
}, | ||
type: 'transaction', | ||
}); | ||
}, | ||
); |
8 changes: 8 additions & 0 deletions
8
dev-packages/browser-integration-tests/suites/public-api/startSpan/standalone/init.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
tracesSampleRate: 1.0, | ||
}); |
1 change: 1 addition & 0 deletions
1
dev-packages/browser-integration-tests/suites/public-api/startSpan/standalone/subject.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Sentry.startSpan({ name: 'standalone_segment_span', experimental: { standalone: true } }, () => {}); |
48 changes: 48 additions & 0 deletions
48
dev-packages/browser-integration-tests/suites/public-api/startSpan/standalone/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { SpanEnvelope } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { | ||
getFirstSentryEnvelopeRequest, | ||
properFullEnvelopeRequestParser, | ||
shouldSkipTracingTest, | ||
} from '../../../../utils/helpers'; | ||
|
||
sentryTest('sends a segment span envelope', async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
const spanEnvelope = await getFirstSentryEnvelopeRequest<SpanEnvelope>(page, url, properFullEnvelopeRequestParser); | ||
|
||
const headers = spanEnvelope[0]; | ||
const item = spanEnvelope[1][0]; | ||
|
||
const itemHeader = item[0]; | ||
const spanJson = item[1]; | ||
|
||
expect(headers).toEqual({ | ||
sent_at: expect.any(String), | ||
}); | ||
|
||
expect(itemHeader).toEqual({ | ||
type: 'span', | ||
}); | ||
|
||
expect(spanJson).toEqual({ | ||
data: { | ||
'sentry.origin': 'manual', | ||
'sentry.sample_rate': 1, | ||
'sentry.source': 'custom', | ||
}, | ||
description: 'standalone_segment_span', | ||
origin: 'manual', | ||
span_id: expect.stringMatching(/^[0-9a-f]{16}$/), | ||
start_timestamp: expect.any(Number), | ||
timestamp: expect.any(Number), | ||
trace_id: expect.stringMatching(/^[0-9a-f]{32}$/), | ||
is_segment: true, | ||
segment_id: spanJson.span_id, | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: I think this should be:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually wait no, it should be:
as if we are sending (theoretically) a standalone span that is not the root span, then it should have the root span id as segment_id!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering when a standalone span is not a root (=== segment) span 🤔 Is this for span streaming?
Regardless, I'll make the change. For now, it should lead to the same outcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So as a result of the change, the one test that tests the hypothetical "standalone span while active span tree" scenario now shows that
is_segment
would no longer be set andsegment_id
is the id of the span tree's root span. Which I guess makes sense.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this would be span streaming then basically! So not really anything we'll do now, but "technically correct" 😅
I think the behavior for the test is correct then! The span would be sent on it's own, would not be a segment span, and the segment id would be the id of the root span! 👍