Skip to content

Instantly share code, notes, and snippets.

@jpkrohling
Created August 8, 2022 20:04
Show Gist options
  • Save jpkrohling/8ed1b03080b52aa46fce3498b5483217 to your computer and use it in GitHub Desktop.
Save jpkrohling/8ed1b03080b52aa46fce3498b5483217 to your computer and use it in GitHub Desktop.
Using OTLP gRPC for nodejs with Grafana Cloud Traces
/* tracing.js */
const grpc = require('@grpc/grpc-js');
// Require dependencies
const opentelemetry = require("@opentelemetry/sdk-node");
const { getNodeAutoInstrumentations } = require("@opentelemetry/auto-instrumentations-node");
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-grpc');
const metadata = new grpc.Metadata();
// after "Basic", comes the output of:
// echo -n username:password | base64 -w 0
metadata.set('authorization', 'Basic MTIzNDU6dGhla2V5');
const exporter = new OTLPTraceExporter({
url: 'tempo-us-central1.grafana.net:443',
credentials: grpc.credentials.createSsl(),
metadata,
});
const sdk = new opentelemetry.NodeSDK({
traceExporter: exporter,
instrumentations: [getNodeAutoInstrumentations()]
});
sdk.start()
@jpkrohling
Copy link
Author

Use this tutorial, but instead of the tracing.js they provide, use the one from the Gist:

https://opentelemetry.io/docs/instrumentation/js/getting-started/nodejs/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment