docs icon indicating copy to clipboard operation
docs copied to clipboard

Add basic console output to the tracing docs

Open andrew-walford-prisma opened this issue 2 years ago • 0 comments

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(); } '''

andrew-walford-prisma avatar Aug 16 '22 08:08 andrew-walford-prisma