Hello i have a app in NESTJS and im trying to send my data using OTP to NewRelic.
To reach it i made this code:
//tracing.ts
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { NodeSDK } from '@opentelemetry/sdk-node';
import * as process from 'process';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto';
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
const traceExporter = new OTLPTraceExporter({
url: 'https://otlp.nr-data.net/v1/traces', // OTLP endpoint
headers: {
'api-key': 'z', // Replace with your license key
},
});
export const otelSDK = new NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: `nestjs-otel`, // update this to a more relevant name for you!
}),
traceExporter: traceExporter,
metricReader: new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter({
url: 'https://otlp.nr-data.net/v1/metrics', // url is optional and can be omitted - default is http://localhost:4318/v1/metrics
headers: {
'api-key': 'zzz', // Replace with your license key
},
// an optional object containing custom headers to be sent with each request
}),
}),
spanProcessor: new SimpleSpanProcessor(traceExporter),
instrumentations: [new HttpInstrumentation(), new ExpressInstrumentation()],
});
// gracefully shut down the SDK on process exit
process.on('SIGTERM', () => {
otelSDK
.shutdown()
.then(
() => console.log('SDK shut down successfully'),
(err) => console.log('Error shutting down SDK', err),
)
.finally(() => process.exit(0));
});
//Main TS
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(
new ValidationPipe({
transformOptions: {
enableImplicitConversion: true,
},
}),
);
app.useGlobalPipes(new ValidationPipe());
app.useGlobalFilters(new AllExceptionsFilter());
await otelSDK.start();
await app.listen(3000);
}
I the data gets into new relic,
Anyone know how to slove the issue?