From bc61a3319c650c315632deb322282ab095538634 Mon Sep 17 00:00:00 2001 From: surbhigarg92 Date: Tue, 7 Jan 2025 17:27:34 +0530 Subject: [PATCH] chore: Update end to end tracing documentation --- OBSERVABILITY.md | 10 +++++++++- samples/observability-traces.js | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/OBSERVABILITY.md b/OBSERVABILITY.md index 0d03b06fb..92340cd98 100644 --- a/OBSERVABILITY.md +++ b/OBSERVABILITY.md @@ -88,8 +88,9 @@ const spanner = new Spanner({ In addition to client-side tracing, you can opt in for end-to-end tracing. End-to-end tracing helps you understand and debug latency issues that are specific to Spanner. Refer [here](https://cloud.google.com/spanner/docs/tracing-overview) for more information. -You can opt-in by either: +To configure end-to-end tracing. +1. Opt in for end-to-end tracing. You can opt-in by either: * Setting the environment variable `SPANNER_ENABLE_END_TO_END_TRACING=true` before your application is started * In code, setting `enableEndToEndTracing: true` in your SpannerOptions before creating the Cloud Spanner client @@ -103,6 +104,13 @@ const spanner = new Spanner({ }), ``` +2. Set the trace context propagation in OpenTelemetry. +```javascript +const {propagation} = require('@opentelemetry/api'); +const {W3CTraceContextPropagator} = require('@opentelemetry/core'); +propagation.setGlobalPropagator(new W3CTraceContextPropagator()); +``` + #### OpenTelemetry gRPC instrumentation Optionally, you can enable OpenTelemetry gRPC instrumentation which produces traces of executed remote procedure calls (RPCs) diff --git a/samples/observability-traces.js b/samples/observability-traces.js index 024223acd..86b0b33a8 100644 --- a/samples/observability-traces.js +++ b/samples/observability-traces.js @@ -41,6 +41,11 @@ const provider = new NodeTracerProvider({ }); provider.addSpanProcessor(new BatchSpanProcessor(exporter)); +// Set global propagator to propogate the trace context for end to end tracing. +const {propagation} = require('@opentelemetry/api'); +const {W3CTraceContextPropagator} = require('@opentelemetry/core'); +propagation.setGlobalPropagator(new W3CTraceContextPropagator()); + // Uncomment following line to register global tracerProvider instead // of passing it into SpannerOptions.observabilityOptions. // provider.register();