Archit Garg
03/04/2024, 11:39 AMimport { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { Resource } from '@opentelemetry/resources';
import * as opentelemetry from '@opentelemetry/sdk-node';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { vars } from '../vars';
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
const oltpExporter = new OTLPTraceExporter({
url: `${vars.otlp_trace_collector_url}/v1/traces`,
});
const exporter = new PrometheusExporter({
endpoint: `${vars.otlp_metric_collector_url}/metrics`,
});
const otelSDK = new opentelemetry.NodeSDK({
traceExporter: oltpExporter,
// @ts-ignore
metricReader: new PeriodicExportingMetricReader({
// @ts-ignore
exporter,
}),
instrumentations: [getNodeAutoInstrumentations({
'@opentelemetry/instrumentation-fs': {
enabled: false,
},
})],
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'testing-backend',
}),
});
export { otelSDK };
Prashant Shahi
03/04/2024, 1:10 PMPrashant Shahi
03/04/2024, 1:12 PMconst sdk = new opentelemetry.NodeSDK({
metricReader: new PrometheusExporter({
port: 9464,
}),
traceExporter,
instrumentations: [getNodeAutoInstrumentations()],
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'node_app'
})
});
^ when you use this snippet, you will get the metrics related to http_server
and http_client
in your application itself,
localhost:9464/metrics
SigNoz is an open-source APM. It helps developers monitor their applications & troubleshoot problems, an open-source alternative to DataDog, NewRelic, etc.
Powered by