Skip to content

Commit

Permalink
Instrument manually to avoid collision between collector on Vercel
Browse files Browse the repository at this point in the history
  • Loading branch information
Rindrics committed Nov 4, 2024
1 parent 6f10773 commit 94a05dd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions instrumentation.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ import { SeverityNumber } from "@opentelemetry/api-logs";
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { Resource } from "@opentelemetry/resources";
import {
BatchLogRecordProcessor,
ConsoleLogRecordExporter,
LoggerProvider,
} from "@opentelemetry/sdk-logs";
import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
import { NodeSDK } from "@opentelemetry/sdk-node";
import {
ConsoleSpanExporter,
SimpleSpanProcessor,
} from "@opentelemetry/sdk-trace-base";
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-node";
import { registerOTel } from "@vercel/otel";
import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";

const headers = {
"signoz-access-token": process.env.SIGNOZ_INGESTION_TOKEN,
Expand Down Expand Up @@ -67,13 +69,17 @@ if (process.env.NODE_ENV !== "production") {
const logRecordProcessor = new BatchLogRecordProcessor(logExporter);
loggerProvider.addLogRecordProcessor(logRecordProcessor);

registerOTel({
serviceName: "giselle",
const sdk = new NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: "giselle",
environment: process.env.NEXT_PUBLIC_VERCEL_ENV || "not-set",
}),
metricReader: metricReader,
spanProcessors: [spanProcessor, debugSpanProcessor],
traceExporter: traceExporter,
logRecordProcessor: logRecordProcessor,
});
sdk.start();

export const logger = loggerProvider.getLogger("giselle");
console.log("-- OTEL registered with metrics, traces, and logs --");
Expand Down

0 comments on commit 94a05dd

Please sign in to comment.