Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(core): Add afterEnvelope and flushTraceSpans client hooks#23136
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -718,6 +718,12 @@ export abstract class Client<O extends ClientOptions = ClientOptions> { | ||
| */ | ||
| public on(hook: 'beforeEnvelope', callback: (envelope: Envelope) => void): () => void; | ||
| /** | ||
| * Register a callback for after an envelope has been accepted by the transport. | ||
| * @returns {() => void} A function that, when executed, removes the registered callback. | ||
| */ | ||
| public on(hook: 'afterEnvelope', callback: (envelope: Envelope) => void): () => void; | ||
| /** | ||
| * Register a callback that runs when stack frame metadata should be applied to an event. | ||
| * @returns {() => void} A function that, when executed, removes the registered callback. | ||
| @@ -871,6 +877,14 @@ export abstract class Client<O extends ClientOptions = ClientOptions> { | ||
| */ | ||
| public on(hook: 'flush', callback: () => void): () => void; | ||
| /** | ||
| * A hook that is called when spans of a single trace should be flushed eagerly, | ||
| * ahead of the trace's regular flush point. Only runtimes with a span streaming | ||
| * buffer (e.g. the Cloudflare SDK) listen to this hook. | ||
| * @returns {() => void} A function that, when executed, removes the registered callback. | ||
| */ | ||
| public on(hook: 'flushTraceSpans', callback: (traceId: string) => void): () => void; | ||
| /** | ||
| * A hook that is called when the client is closing | ||
| * @returns {() => void} A function that, when executed, removes the registered callback. | ||
| @@ -1041,6 +1055,11 @@ export abstract class Client<O extends ClientOptions = ClientOptions> { | ||
| */ | ||
| public emit(hook: 'beforeEnvelope', envelope: Envelope): void; | ||
| /** | ||
| * Fire a hook event after an envelope has been accepted by the transport. | ||
| */ | ||
| public emit(hook: 'afterEnvelope', envelope: Envelope): void; | ||
| /** | ||
| * Fire a hook indicating that stack frame metadata should be applied to the event passed to the hook. | ||
| */ | ||
| @@ -1165,6 +1184,11 @@ export abstract class Client<O extends ClientOptions = ClientOptions> { | ||
| */ | ||
| public emit(hook: 'flush'): void; | ||
| /** | ||
| * Fire a hook event indicating that spans of a single trace should be flushed eagerly. | ||
| */ | ||
| public emit(hook: 'flushTraceSpans', traceId: string): void; | ||
| /** | ||
| * Emit a hook event for client close | ||
| */ | ||
| @@ -1248,7 +1272,9 @@ export abstract class Client<O extends ClientOptions = ClientOptions> { | ||
| if (this._isEnabled() && this._transport) { | ||
| try { | ||
| return await this._transport.send(envelope); | ||
| const result = await this._transport.send(envelope); | ||
| this.emit('afterEnvelope', envelope); | ||
| return result; | ||
sentry[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } catch (reason) { | ||
| DEBUG_BUILD && debug.error('Error while sending envelope:', reason); | ||
| return {}; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -27,6 +27,12 @@ export const spanStreamingIntegration = defineIntegration(() => { | ||
| } | ||
| buffer.add(captureSpan(span, client)); | ||
| }); | ||
| // Lets runtimes flush a single trace eagerly (e.g. the Cloudflare SDK draining | ||
| // a trace the moment its segment ends), without exposing the buffer itself. | ||
| client.on('flushTraceSpans', traceId => { | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is fine since browser ships its own
| ||
| buffer.flush(traceId); | ||
| }); | ||
| }, | ||
| }; | ||
| }) satisfies IntegrationFn; | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
I'm not fully sure why we need this hook yet. Is the idea that we basically do
?
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.
Yes exactly. No sure if there is a better solution for this