Skip to content

Commit dcd14c4

Browse files
committed
feat(node): distributed tracing spans
Adds startSpan, withSpan and getActiveSpan to posthog-node behind a new traces client option, encoding spans as OTLP JSON without an OpenTelemetry dependency.
1 parent aa72a36 commit dcd14c4

38 files changed

Lines changed: 4706 additions & 576 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'posthog-node': minor
3+
'@posthog/core': minor
4+
'@posthog/types': minor
5+
---
6+
7+
Add distributed tracing to `posthog-node`: `withSpan`, `startSpan` and `getActiveSpan`, enabled by a new `traces` client option.

.changeset/otlp-bigint-int64.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@posthog/core': patch
3+
---
4+
5+
Change `bigint` attributes on logs, metrics and spans to send as an int64 rather than as a string.

packages/core/src/__tests__/posthog.flush.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,11 +762,12 @@ describe('PostHog Core', () => {
762762
})
763763

764764
describe('OTLP batch senders', () => {
765-
// Both share one `_sendOtlpBatch`; the table pins them to the same
765+
// All three share one `_sendOtlpBatch`; the table pins them to the same
766766
// classification so a wrapper can't reintroduce a per-signal retry policy.
767767
const senders = {
768768
logs: (client: PostHogCoreTestClient) => client._sendLogsBatch({ resourceLogs: [] }),
769769
metrics: (client: PostHogCoreTestClient) => client._sendMetricsBatch({ resourceMetrics: [] }),
770+
traces: (client: PostHogCoreTestClient) => client._sendTracesBatch({ resourceSpans: [] }),
770771
}
771772

772773
const cases: [number, string][] = [

packages/core/src/index.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ export {
4242
buildResourceAttributes,
4343
getOtlpSeverityNumber,
4444
getOtlpSeverityText,
45-
toOtlpAnyValue,
46-
toOtlpKeyValueList,
4745
} from './logs/logs-utils'
46+
export { toOtlpAnyValue, toOtlpKeyValueList } from './utils/otlp-any-value'
4847
export { PostHogLogs } from './logs'
4948
export type {
5049
BeforeSendLogFn,
@@ -87,6 +86,27 @@ export type {
8786
Metrics,
8887
MetricsConfig,
8988
} from './metrics/types'
89+
export { PostHogTraces } from './traces'
90+
export { SyncSpanContextManager } from './traces/context'
91+
export { NOOP_SPAN } from './traces/span'
92+
export type {
93+
ResolvedTracesConfig,
94+
SendTracesBatchOutcome,
95+
SpanContextManager,
96+
TraceSdkContext,
97+
TracesHost,
98+
} from './traces/types'
99+
// Same barrel convention as logs and metrics for the user-facing tracing types.
100+
export type {
101+
Span,
102+
SpanAttributes,
103+
SpanAttributeValue,
104+
SpanKind,
105+
SpanStatusCode,
106+
SpanTimeInput,
107+
StartSpanOptions,
108+
TracesConfig,
109+
} from './traces/types'
90110
export { uuidv7 } from './vendor/uuidv7'
91111
export * from './cookie'
92112
export * from './posthog-core'

0 commit comments

Comments
 (0)