Skip to content

Commit

Permalink
chore: add otel headers config to support axiom (#724)
Browse files Browse the repository at this point in the history
Co-authored-by: ben <ben@prologe.io>
  • Loading branch information
lrnt and benjaminshafii authored Aug 27, 2024
1 parent fb32c17 commit 038d143
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ WORKER_ACCESS_KEY=secretsecretsecretsecretsecretsecret
######################### OpenTelemetry Variables ################################
OTEL_ENABLED=false
OTEL_EXPORTER_TRACES_ENDPOINT=
OTEL_EXPORTER_METRICS_ENDPOINT=
OTEL_EXPORTER_TRACES_HEADERS=
OTEL_EXPORTER_LOGS_ENDPOINT=
OTEL_EXPORTER_LOGS_HEADERS=
OTEL_EXPORTER_METRICS_ENDPOINT=


########################## POSTHOG VARIABLES ################################
Expand Down
15 changes: 15 additions & 0 deletions packages/otel/env.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import { createEnv } from '@t3-oss/env-core';
import { z } from 'zod';

const stringToJSON = z.string().transform((str, ctx) => {
try {
return JSON.parse(str) as unknown;
} catch (e) {
ctx.addIssue({ code: 'custom', message: 'Invalid JSON' });
return z.NEVER;
}
});

export const env = createEnv({
server: {
OTEL_ENABLED: z
.string()
.optional()
.transform((v) => v === 'true'),
OTEL_EXPORTER_TRACES_ENDPOINT: z.string().url().optional(),
OTEL_EXPORTER_TRACES_HEADERS: stringToJSON
.pipe(z.record(z.string()))
.optional(),
OTEL_EXPORTER_LOGS_ENDPOINT: z.string().url().optional(),
OTEL_EXPORTER_LOGS_HEADERS: stringToJSON
.pipe(z.record(z.string()))
.optional(),
OTEL_EXPORTER_METRICS_ENDPOINT: z.string().url().optional(),
NODE_ENV: z.enum(['development', 'production']).default('development')
},
Expand Down
6 changes: 4 additions & 2 deletions packages/otel/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const setupOpentelemetry = ({
traceProvider.addSpanProcessor(
new BatchSpanProcessor(
new OTLPTraceExporter({
url: env.OTEL_EXPORTER_TRACES_ENDPOINT
url: env.OTEL_EXPORTER_TRACES_ENDPOINT,
headers: env.OTEL_EXPORTER_TRACES_HEADERS
})
)
);
Expand All @@ -42,7 +43,8 @@ export const setupOpentelemetry = ({
loggerProvider.addLogRecordProcessor(
new BatchLogRecordProcessor(
new OTLPLogExporter({
url: env.OTEL_EXPORTER_LOGS_ENDPOINT
url: env.OTEL_EXPORTER_LOGS_ENDPOINT,
headers: env.OTEL_EXPORTER_LOGS_HEADERS
})
)
);
Expand Down

0 comments on commit 038d143

Please sign in to comment.