From 66da9a432c3a242809c5c17027741b9df90f3ffd Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Wed, 11 Sep 2019 10:32:43 -0700 Subject: [PATCH] feat: add basic tracer usage (#239) --- packages/opentelemetry-basic-tracer/README.md | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/opentelemetry-basic-tracer/README.md b/packages/opentelemetry-basic-tracer/README.md index ff810f8bb1e..a4dff0011f5 100644 --- a/packages/opentelemetry-basic-tracer/README.md +++ b/packages/opentelemetry-basic-tracer/README.md @@ -18,9 +18,28 @@ npm install --save @opentelemetry/basic-tracer ## Usage ``` -const opentelemetry = require('@opentelemetry/basic-tracer'); +const opentelemetry = require('@opentelemetry/core'); +const { BasicTracer } = require('@opentelemetry/basic-tracer'); +const { NoopScopeManager } = require('@opentelemetry/scope-base'); + +// To start a trace, you first need to initialize the Tracer. +// NOTE: the default OpenTelemetry tracer does not record any tracing information. +const tracer = new BasicTracer({ + scopeManager: new NoopScopeManager() +}); + +// Initialize the OpenTelemetry APIs to use the BasicTracer bindings +opentelemetry.initGlobalTracer(tracer); + +// To create a span in a trace, we used the global singleton tracer to start a new span. +const span = opentelemetry.getTracer().startSpan('foo'); + +// Create an Attributes +span.setAttribute('key', 'value'); + +// We must end the spans so they becomes available for exporting. +span.end(); -// TODO: DEMONSTRATE API ``` ## Useful links