Trace a single endpoint with AWS Distro for OpenTelemetry (ADOT)

18 views Asked by At

I'm working on a Node.js application with ADOT. The issue is that by default ADOT creates traces for the entire app. How can I create traces for a specific endpoint?

This is the way I'm using ADOT:

tracer.ts

import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions'
import { Resource } from '@opentelemetry/resources'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
import * as otel from '@opentelemetry/sdk-node'

const traceExporter = new OTLPTraceExporter({
    url: 'http://localhost:4318/v1/traces'
})

const sdk = new otel.NodeSDK(
    {
        traceExporter,
        instrumentations: [getNodeAutoInstrumentations()],
        resource: new Resource(
            {
                [SEMRESATTRS_SERVICE_NAME]: "nodejs-trace"
            }
        )
    }
)

export default sdk

main.ts

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import sdk from './tracer'

async function bootstrap() {
  sdk.start();
  const app = await NestFactory.create(AppModule);
  await app.listen(3000);
}
bootstrap();
0

There are 0 answers