Skip to content

Commit df4ac70

Browse files
committed
Support environment for cloudflare workers
1 parent e241f3a commit df4ac70

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

.changeset/heavy-poems-fly.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": patch
3+
---
4+
5+
Support environment for Cloudflare workers

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ to your `.dev.vars` file:
8585

8686
```sh
8787
LOGFIRE_TOKEN=your-write-token
88+
LOGFIRE_ENVIRONMENT=development
8889
```
8990

91+
The `LOGFIRE_ENVIRONMENT` variable is optional and can be used to specify the environment for the service.
92+
9093
For production deployment, check the
9194
[Cloudflare documentation for details on managing and deploying secrets](https://developers.cloudflare.com/workers/configuration/secrets/).
9295

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/logfire-cf-workers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
},
5151
"dependencies": {
5252
"@pydantic/logfire-api": "*",
53-
"@pydantic/otel-cf-workers": "^1.0.0-rc.51"
53+
"@pydantic/otel-cf-workers": "^1.0.0-rc.53"
5454
},
5555
"devDependencies": {
5656
"@cloudflare/workers-types": "4.20250311.0",

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export interface CloudflareConfigOptions {
1414

1515
type Env = Record<string, string | undefined>
1616

17-
type ConfigOptionsBase = Pick<TraceConfig, 'fetch' | 'handlers' | 'instrumentation' | 'propagator' | 'sampling' | 'scope' | 'service'>
17+
type ConfigOptionsBase = Pick<
18+
TraceConfig,
19+
'environment' | 'fetch' | 'handlers' | 'instrumentation' | 'propagator' | 'sampling' | 'scope' | 'service'
20+
>
1821

1922
export interface InProcessConfigOptions extends ConfigOptionsBase {
2023
baseUrl?: string
@@ -25,11 +28,13 @@ export interface TailConfigOptions extends ConfigOptionsBase {}
2528

2629
function getInProcessConfig(config: InProcessConfigOptions): (env: Env) => TraceConfig {
2730
return (env: Env): TraceConfig => {
28-
const { LOGFIRE_TOKEN: token = '' } = env
31+
const { LOGFIRE_ENVIRONMENT: envDeploymentEnvironment, LOGFIRE_TOKEN: token = '' } = env
2932

3033
const baseUrl = resolveBaseUrl(env, config.baseUrl, token)
34+
const resolvedEnvironment = config.environment ?? envDeploymentEnvironment
3135

3236
return Object.assign({}, config, {
37+
environment: resolvedEnvironment,
3338
exporter: {
3439
headers: { Authorization: token },
3540
url: `${baseUrl}/v1/traces`,

0 commit comments

Comments
 (0)