-
Notifications
You must be signed in to change notification settings - Fork 335
feat(node): distributed tracing spans #4579
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
+9,431
−27
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
e5e089e
feat(node): distributed tracing spans
turnipdabeets 5f7b2ff
docs(node): regenerate the references for the withSpan doc comment
turnipdabeets 9ca920e
feat(node): bound live spans by count and age
turnipdabeets b07c9eb
Merge remote-tracking branch 'origin/main' into feat/traces-node-mvp
turnipdabeets bf5e7af
fix(traces): pass an inbound trace through when tracing is off
turnipdabeets 02cd40a
Merge remote-tracking branch 'origin/main' into feat/traces-node-mvp
turnipdabeets dc7aed3
fix(traces): count spans dropped at the consent gates
turnipdabeets 92309f4
feat(node): emit os.name and os.version on spans (#4679)
turnipdabeets b5b0a84
Merge main into feat/traces-node-mvp
turnipdabeets 0c640f2
feat(traces): propagate the inbound sampled flag and parent remotenes…
turnipdabeets d7ffe61
refactor(traces): keep the traces plumbing off the public API (#4773)
turnipdabeets 44b53a1
fix(traces): reject a traceparent W3C requires a vendor to ignore (#4…
turnipdabeets 24d51e3
fix(traces): keep inbound context and flag a future span start (#4790)
turnipdabeets 9d10ad4
feat(node): beforeSpanSend hook and per-span limits (#4584)
turnipdabeets 815d53d
feat(traces): cap the attributes on a span event
turnipdabeets 4796890
fix(traces): stop a nullish value spending an event's attribute slot
turnipdabeets 1ce3bc3
chore: drop an unrelated changeset committed by mistake
turnipdabeets 701bba2
docs(traces): fold the traces changesets into one, and tidy stray com…
turnipdabeets 8e3573f
Merge remote-tracking branch 'origin/feat/traces-node-mvp' into fix/t…
turnipdabeets a545925
docs(traces): cut the tracing changeset to a single line
turnipdabeets 94679e7
Merge remote-tracking branch 'origin/feat/traces-node-mvp' into fix/t…
turnipdabeets 6fc61fa
chore: drop the unrelated RN changeset again
turnipdabeets 8c3e21c
Merge remote-tracking branch 'origin/feat/traces-node-mvp' into fix/t…
turnipdabeets a9e76dc
refactor(traces): keep the per-event attribute cap internal
turnipdabeets 833a165
fix(traces): clamp drop counts to uint32 and correct the size comments
turnipdabeets 4027827
docs(traces): mark cross-package plumbing internal and correct the pa…
turnipdabeets 2122d69
Merge remote-tracking branch 'origin/feat/traces-node-mvp' into tmp/4…
turnipdabeets 822383b
Merge remote-tracking branch 'origin/main' into feat/traces-node-mvp
turnipdabeets 3b13d60
Merge branch 'feat/traces-node-mvp' into fix/traces-event-attribute-cap
turnipdabeets 2581b66
fix(traces): keep the inbound trace context through nested spans
turnipdabeets 54705cf
Merge remote-tracking branch 'origin/feat/traces-node-mvp' into fold/…
turnipdabeets b2aaa72
feat(traces): report a span's limit drops once, event attributes incl…
turnipdabeets c8f9a66
fix(traces): follow Jon's revised tracestate and parent-doc review
turnipdabeets ccfc0c9
Merge remote-tracking branch 'origin/feat/traces-node-mvp' into sync/…
turnipdabeets 880b68d
feat(traces): cap the attributes on a span event (#4792)
turnipdabeets 43425f8
docs(changeset): name the span hook and per-span caps that ship with …
turnipdabeets 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
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,6 @@ | ||
| --- | ||
| 'posthog-node': patch | ||
| '@posthog/core': patch | ||
| --- | ||
|
|
||
| Stop a throwing getter in `metrics.resourceAttributes` from breaking every metrics export — the key is recorded as `[Unserializable]` instead. |
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,7 @@ | ||
| --- | ||
| 'posthog-node': minor | ||
| '@posthog/core': minor | ||
| '@posthog/types': minor | ||
| --- | ||
|
|
||
| Add experimental distributed tracing to `posthog-node`: `startSpan`, `withSpan` and `getActiveSpan` record spans against a new `traces` client option. A service with tracing off still forwards an inbound `traceparent`, including from spans nested inside the one that received it, so a distributed trace is not severed. A `traceparent` may be passed as the one-element array `req.headersDistinct` gives. A `beforeSpanSend` hook sees every span before it is exported and may edit or drop it, and `maxAttributesPerSpan`, `maxEventsPerSpan`, `maxAttributeValueLength`, `maxLiveSpans` and `maxSpanAgeMs` bound what a single span and a single process may hold. |
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,49 @@ | ||
| import { createTestClient, PostHogCoreTestClient, PostHogCoreTestClientMocks } from '@/testing' | ||
|
|
||
| // One `_sendOtlpBatch` serves logs, metrics and traces, and the endpoint each one | ||
| // authenticates against is a single argument away from the wrong scheme. These pin | ||
| // all three so a flipped argument fails here rather than shipping the project key | ||
| // in a header the logs endpoint does not expect. | ||
| describe('OTLP batch auth', () => { | ||
| let posthog: PostHogCoreTestClient | ||
| let mocks: PostHogCoreTestClientMocks | ||
|
|
||
| beforeEach(() => { | ||
| ;[posthog, mocks] = createTestClient('TEST_API_KEY', { | ||
| host: 'http://example.com', | ||
| preloadFeatureFlags: false, | ||
| disableCompression: true, | ||
| }) | ||
| mocks.fetch.mockResolvedValue({ | ||
| status: 200, | ||
| text: () => Promise.resolve('ok'), | ||
| json: () => Promise.resolve({ status: 'ok' }), | ||
| }) | ||
| }) | ||
|
|
||
| const lastCall = (): [string, any] => mocks.fetch.mock.calls[mocks.fetch.mock.calls.length - 1] as [string, any] | ||
|
|
||
| it('sends logs to the query-token endpoint with no Authorization header', async () => { | ||
| await posthog._sendLogsBatch({ resourceLogs: [] } as any) | ||
|
|
||
| const [url, options] = lastCall() | ||
| expect(url).toBe('http://example.com/i/v1/logs?token=TEST_API_KEY') | ||
| expect(options.headers).not.toHaveProperty('Authorization') | ||
| }) | ||
|
|
||
| it('sends metrics to the query-token endpoint with no Authorization header', async () => { | ||
| await posthog._sendMetricsBatch({ resourceMetrics: [] } as any) | ||
|
|
||
| const [url, options] = lastCall() | ||
| expect(url).toBe('http://example.com/i/v1/metrics?token=TEST_API_KEY') | ||
| expect(options.headers).not.toHaveProperty('Authorization') | ||
| }) | ||
|
|
||
| it('sends traces with bearer auth and no token in the query string', async () => { | ||
| await posthog._sendTracesBatch({ resourceSpans: [] } as any) | ||
|
|
||
| const [url, options] = lastCall() | ||
| expect(url).toBe('http://example.com/i/v1/traces') | ||
| expect(options.headers.Authorization).toBe('Bearer TEST_API_KEY') | ||
| }) | ||
| }) |
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.
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.
Nit: mark cross-package plumbing as
@internal.Please tag
PostHogTraces,SyncSpanContextManager,inertSpan,runWithActiveSpan,resolveTracesConfig,ResolvedTracesConfig, andTraceSdkContext. They are exported from the published core package but are not intended as stable public API.Use the existing cross-package JSDoc wording. Leave
SpanContextManagerpublic because it appears in the protected initialization hook. Non-blocking.Sources: core exports · existing internal convention.
Agent-assisted review.
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.
Done in
40278277f. All seven tagged at the declaration rather than the re-export,SpanContextManagerleft public.pnpm generate-referencesis unchanged by it.