-
Notifications
You must be signed in to change notification settings - Fork 407
fix(serverless): flush configured telemetry on Vercel #9735
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
Open
wconti27
wants to merge
33
commits into
master
Choose a base branch
from
conti/vercel-waituntil-flush-callback
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
ecb9c67
fix(serverless): retain telemetry on Vercel
wconti27 3071c5d
fix(serverless): retain active telemetry exports
wconti27 2cd52d1
refactor(serverless): isolate Vercel lifecycle adapter
wconti27 a8011be
docs(otlp): clarify logger flush registration
wconti27 c8eb4e2
docs(serverless): clarify telemetry flush registry
wconti27 f077780
test(otlp): cover multi-batch log flushing
wconti27 295ba2d
refactor(serverless): bound flushing in tracer
wconti27 fa7c7dd
fix(serverless): retain span stats and bounded log batches
wconti27 b4dc847
test(span-stats): cover in-flight export flush
wconti27 49242e9
fix(serverless): wait for Vercel response completion
wconti27 7754861
fix(serverless): order Vercel telemetry flushing
wconti27 6d1e78a
fix(exporters): clean up failed flush records
wconti27 af34546
fix(serverless): retain outer Vercel telemetry
wconti27 7caaca0
fix(exporters): retain in-flight traces after flush failure
wconti27 7370141
fix(serverless): retain telemetry on Vercel
wconti27 dcb9d69
fix(serverless): retain active telemetry exports
wconti27 59de657
refactor(serverless): isolate Vercel lifecycle adapter
wconti27 99a4454
docs(otlp): clarify logger flush registration
wconti27 f5c3d82
docs(serverless): clarify telemetry flush registry
wconti27 6791765
test(otlp): cover multi-batch log flushing
wconti27 94b7729
refactor(serverless): bound flushing in tracer
wconti27 ab88223
fix(serverless): retain span stats and bounded log batches
wconti27 54ba4d3
test(span-stats): cover in-flight export flush
wconti27 199cebb
fix(serverless): wait for Vercel response completion
wconti27 e299783
fix(serverless): order Vercel telemetry flushing
wconti27 3ff70e5
fix(exporters): clean up failed flush records
wconti27 614e2b1
fix(serverless): retain outer Vercel telemetry
wconti27 98cf0f9
fix(exporters): retain in-flight traces after flush failure
wconti27 5a7fa90
fix(serverless): retain runtime metrics and span stats
wconti27 2360f69
merge: retain PR history after rebase
wconti27 1bb364d
Merge branch 'master' into conti/vercel-waituntil-flush-callback
wconti27 859506d
fix(serverless): retain all Vercel telemetry flushes
wconti27 27b2693
fix(serverless): retain remaining Vercel telemetry
wconti27 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| 'use strict' | ||
|
|
||
| const log = require('./log') | ||
|
|
||
| /** | ||
| * @typedef {(done: () => void) => void | Promise<void>} TelemetryFlusher | ||
| */ | ||
|
|
||
| /** @type {Set<TelemetryFlusher>} */ | ||
| const telemetryFlushers = new Set() | ||
|
|
||
| /** | ||
| * Registers a configured telemetry pipeline so serverless lifecycle retention | ||
| * waits for its final export alongside trace delivery. | ||
| * @param {TelemetryFlusher} flusher | ||
| * @returns {() => void} Removes this pipeline when its provider is replaced. | ||
| */ | ||
| function registerTelemetryFlusher (flusher) { | ||
| telemetryFlushers.add(flusher) | ||
| // Avoid retaining a replaced provider or flushing it alongside the new one. | ||
| return () => telemetryFlushers.delete(flusher) | ||
| } | ||
|
|
||
| /** | ||
| * Flushes the trace exporter and every registered telemetry pipeline. | ||
| * @param {{ | ||
| * _exporter?: { flush?: TelemetryFlusher }, | ||
| * _processor?: { _stats?: { forceFlush?: TelemetryFlusher } } | ||
| * }|undefined} tracer | ||
| * @param {() => void} [done] | ||
| * @param {{ timeout?: number }} [options] | ||
| */ | ||
| function flushAll (tracer, done, options) { | ||
| const traceExporter = tracer?._exporter | ||
| const traceFlusher = traceExporter?.flush | ||
| const spanStatsFlusher = tracer?._processor?._stats?.forceFlush | ||
| // TODO: Include DSM after DataStreamsProcessor exposes a completion-aware flush API. | ||
| let pending = telemetryFlushers.size + | ||
| (typeof traceFlusher === 'function' ? 1 : 0) + | ||
| (typeof spanStatsFlusher === 'function' ? 1 : 0) | ||
|
wconti27 marked this conversation as resolved.
Outdated
wconti27 marked this conversation as resolved.
Outdated
|
||
| let completed = false | ||
| let timeout | ||
|
|
||
| const finish = () => { | ||
| if (completed) return | ||
| completed = true | ||
| clearTimeout(timeout) | ||
| done?.() | ||
| } | ||
| const complete = () => { | ||
| if (--pending === 0) finish() | ||
| } | ||
|
|
||
| if (pending === 0) return finish() | ||
| if (options?.timeout) { | ||
| timeout = setTimeout(() => { | ||
| log.warn('Timed out waiting for telemetry flush after %dms', options.timeout) | ||
| finish() | ||
| }, options.timeout) | ||
| } | ||
|
|
||
| const flush = flusher => { | ||
| let flushed = false | ||
| const onFlushed = error => { | ||
| if (flushed) return | ||
| flushed = true | ||
| if (error) log.error('Error flushing telemetry pipeline:', error) | ||
| complete() | ||
| } | ||
| try { | ||
| const result = flusher(onFlushed) | ||
| result?.then(onFlushed, error => onFlushed(error)) | ||
| } catch (error) { | ||
| onFlushed(error) | ||
| } | ||
| } | ||
|
|
||
| if (typeof traceFlusher === 'function') { | ||
| flush(done => traceFlusher.call(traceExporter, done)) | ||
|
wconti27 marked this conversation as resolved.
Outdated
wconti27 marked this conversation as resolved.
Outdated
|
||
| } | ||
| if (typeof spanStatsFlusher === 'function') { | ||
| flush(done => spanStatsFlusher.call(tracer._processor._stats, done)) | ||
| } | ||
| for (const flusher of telemetryFlushers) flush(flusher) | ||
|
wconti27 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| module.exports = { flushAll, registerTelemetryFlusher } | ||
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
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.
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.
Uh oh!
There was an error while loading. Please reload this page.