Krish909
Krish909

Reputation: 105

Opentelemetry Configuration with datadog agent nestjs

I am trying to send the backend traces to datadog through datadog agent from opentelementry in a nestjs application, but my tracing agent is not able to receive any data , trying to send the backend traces to datadog, but could not find anything about it on nestjs documentation.

tracing.ts:

    import { NodeSDK } from '@opentelemetry/sdk-node';
    // import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
    import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
    import {
      SimpleSpanProcessor,
      ConsoleSpanExporter,
    } from '@opentelemetry/tracing';
    import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
    import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
    import { Resource } from '@opentelemetry/resources';
    import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
    
    const traceExporter = new OTLPTraceExporter({
      url: 'http://localhost:4317/v1/traces',
    });
    
    const traceProvider = new NodeTracerProvider({
      resource: new Resource({
        [SemanticResourceAttributes.SERVICE_NAME]: 'RestAPI', //"YOUR-SERVICE-NAME",
      }),
    }) as any;
    
    const otelSDK = new NodeSDK({
      instrumentations: [getNodeAutoInstrumentations()],
    });
    
    traceProvider.register();
    
    // export spans to console (useful for debugging)
    traceProvider.addSpanProcessor(
      new SimpleSpanProcessor(new ConsoleSpanExporter()),
    );
    // export spans to opentelemetry collector
    traceProvider.addSpanProcessor(new SimpleSpanProcessor(traceExporter));
    
    export default otelSDK;
    
    otelSDK
      .start()
      .then(() => {
        console.log('Tracing initialized');
      })
      .catch((error) => console.log('Error initializing tracing', error));
    
    process.on('SIGTERM', () => {
      otelSDK
        .shutdown()
        .then(() => console.log('Tracing terminated'))
        .catch((error) => console.log('Error terminating tracing', error))
        .finally(() => process.exit(0));
    });

datadog.yaml:

    api_key: xvygjhkfklljdsfhdslkhfsd
    
    proxy:
      https: http://Username:password@URL
      http: http://Username:password@URL
      no_proxy:
        - localhost
        - 127.0.0.1
    
    otlp_config:
      receiver:
        protocols:
          grpc:
            endpoint: localhost:4317
          http:
            endpoint: localhost:4318
    
    log: debug

trace-agent.log:

2023-03-28 09:11:57 CDT | TRACE | INFO | (run.go:253 in Info) | No data received
2023-03-28 09:11:57 CDT | TRACE | WARN | (run.go:263 in Warnf) | Failed to read pid from /proc/self: readlink /proc/self: no such file or directory. Falling back to os.Getpid

Upvotes: 0

Views: 1387

Answers (1)

Yang Song
Yang Song

Reputation: 11

It looks like you are using a HTTP exporter but configuring it to send to the gRPC endpoint.

import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
...
const traceExporter = new OTLPTraceExporter({
  url: 'http://localhost:4317/v1/traces',
});
otlp_config:
  receiver:
    protocols:
      grpc:
        endpoint: localhost:4317
      http:
        endpoint: localhost:4318

The url should instead be:

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

Upvotes: 1

Related Questions