Skip to content

Commit 3203828

Browse files
committed
Additional span processors for CF workers
1 parent f998d44 commit 3203828

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

.changeset/vast-taxes-juggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@pydantic/logfire-cf-workers": minor
3+
---
4+
5+
Support additional span processors for cf workers

packages/logfire-cf-workers/src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type ReadableSpan, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'
1+
import { type ReadableSpan, SimpleSpanProcessor, SpanProcessor } from '@opentelemetry/sdk-trace-base'
22
import * as logfireApi from '@pydantic/logfire-api'
33
import { resolveBaseUrl, serializeAttributes, ULIDGenerator } from '@pydantic/logfire-api'
44
import { instrument as baseInstrument, TraceConfig } from '@pydantic/otel-cf-workers'
@@ -15,6 +15,10 @@ type ConfigOptionsBase = Pick<
1515
>
1616

1717
export interface InProcessConfigOptions extends ConfigOptionsBase {
18+
/**
19+
* Additional span processors to add to the tracer provider.
20+
*/
21+
additionalSpanProcessors?: SpanProcessor[]
1822
baseUrl?: string
1923
/**
2024
* Whether to log the spans to the console in addition to sending them to the Logfire API.
@@ -36,7 +40,11 @@ function getInProcessConfig(config: InProcessConfigOptions): (env: Env) => Trace
3640
const baseUrl = resolveBaseUrl(env, config.baseUrl, token)
3741
const resolvedEnvironment = config.environment ?? envDeploymentEnvironment
3842

39-
const additionalSpanProcessors = config.console ? [new SimpleSpanProcessor(new LogfireCloudflareConsoleSpanExporter())] : []
43+
const additionalSpanProcessors = config.additionalSpanProcessors ?? []
44+
45+
if (config.console) {
46+
additionalSpanProcessors.push(new SimpleSpanProcessor(new LogfireCloudflareConsoleSpanExporter()))
47+
}
4048

4149
return Object.assign({}, config, {
4250
additionalSpanProcessors,

0 commit comments

Comments
 (0)