web
web copied to clipboard
Add basic console output to the tracing docs
If a user wants to play with tracing locally, the easiest way would be to output to the console, as described by Daniel in this thread. This uses ConsoleSpanExporter from '@opentelemetry/sdk-trace-base'.
This is probably a good use case to add to the tracing docs.
import { Resource } from "@opentelemetry/resources";
import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
import {
BasicTracerProvider,
ConsoleSpanExporter,
SimpleSpanProcessor,
} from "@opentelemetry/sdk-trace-base";
import { AsyncHooksContextManager } from "@opentelemetry/context-async-hooks";
import * as api from "@opentelemetry/api";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { PrismaInstrumentation } from "@prisma/instrumentation";
export function otelSetup() {
const contextManager = new AsyncHooksContextManager().enable();
api.context.setGlobalContextManager(contextManager);
const consoleExporter = new ConsoleSpanExporter();
const provider = new BasicTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: "test-tracing-service",
[SemanticResourceAttributes.SERVICE_VERSION]: "1.0.0",
}),
});
provider.addSpanProcessor(new SimpleSpanProcessor(consoleExporter));
registerInstrumentations({
tracerProvider: provider,
instrumentations: [new PrismaInstrumentation()],
});
provider.register();
}
I'm on the fence on whether we should add this. If you are new to tracing and use the console Exporter, the tracing output is very boring and it won't be that obvious what you are seeing and how useful it. Whereas the tracing with jaeger will give a really good visual display of what is happening.