Skip to content

Commit 061c2fb

Browse files
committed
feat: add OtlpTraceService
1 parent e9bcbe4 commit 061c2fb

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { SimpleStructuredLogger } from "@trigger.dev/core/v3/utils/structuredLogger";
2+
import { buildOtlpTracePayload, type OtlpTraceOptions } from "../otlpPayload.js";
3+
4+
export type OtlpTraceServiceOptions = {
5+
endpointUrl: string;
6+
timeoutMs?: number;
7+
};
8+
9+
export class OtlpTraceService {
10+
private readonly logger = new SimpleStructuredLogger("otlp-trace");
11+
12+
constructor(private opts: OtlpTraceServiceOptions) {}
13+
14+
/** Fire-and-forget: build payload and send to the configured OTLP endpoint */
15+
emit(opts: OtlpTraceOptions): void {
16+
const payload = buildOtlpTracePayload(opts);
17+
18+
fetch(`${this.opts.endpointUrl}/v1/traces`, {
19+
method: "POST",
20+
headers: { "Content-Type": "application/json" },
21+
body: JSON.stringify(payload),
22+
signal: AbortSignal.timeout(this.opts.timeoutMs ?? 5_000),
23+
}).catch((err) => {
24+
this.logger.warn("failed to send compute trace span", {
25+
error: err instanceof Error ? err.message : String(err),
26+
});
27+
});
28+
}
29+
}

0 commit comments

Comments
 (0)