Closed SandervanL closed 2 months ago
This issue was being caused by registerOtel
being initialized without a traceExporter
, which defaulted sending the logs to http://localhost:4318/v1/traces
, but I did not setup an Otel Collector to be running there. That means a fetch error. It would be great if in the future a more verbose error could be setup.
I solved it as follows (no instrumentation when no Azure Application Insights connection string is configured.
import { env } from "~/env";
import type { SpanExporter } from "@opentelemetry/sdk-trace-base";
import { registerOTel } from "@vercel/otel";
export async function register() {
let traceExporter: SpanExporter | undefined;
if (
typeof "window" === "undefined" &&
env.APPLICATIONINSIGHTS_CONNECTION_STRING != null
) {
const { AzureMonitorTraceExporter } = await import(
"@azure/monitor-opentelemetry-exporter"
);
traceExporter = new AzureMonitorTraceExporter({
connectionString: env.APPLICATIONINSIGHTS_CONNECTION_STRING,
});
registerOTel({
serviceName: env.APPLICATIONINSIGHTS_SERVICE_NAME,
traceExporter,
});
}
}
When using
@vercel/otel
locally (using next dev), on startup, I get the following error. Am I doing something wrong?Then for each request, I get the following:
With as a cause:
This is my
instrumentation.ts
:My
package.json
: