This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import "github.com/lightstep/otel-launcher-go/launcher" | |
| func main() { | |
| otel := launcher.ConfigureOpentelemetry( | |
| launcher.WithServiceName("robochef9000"), | |
| launcher.WithServiceVersion("v1.2.3"), | |
| launcher.WithAccessToken("ls-access-token"), | |
| ) | |
| defer otel.Shutdown() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func main() { | |
| // configure headers | |
| headers := map[string]string{ | |
| "lightstep-access-token": "ls-access-token", | |
| } | |
| // configure TLS credentials | |
| secureOption := otlp.WithTLSCredentials(credentials.NewClientTLSFromCert()) | |
| //configure an OTLP exporter | |
| exporter, err := otlp.NewExporter( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require('express'); | |
| const app = express(); | |
| app.get('/hello', (req, res) => { | |
| res.status(200).send('Hello World'); | |
| }); | |
| app.listen(9000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require('http'); | |
| function makeRequest() { | |
| http.get({ | |
| host: 'localhost', | |
| port: 9000, | |
| path: '/hello', | |
| }, (response) => { | |
| const body = []; | |
| response.on('data', (chunk) => body.push(chunk)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { lightstep } = require('lightstep-opentelemetry-launcher-node'); | |
| const sdk = lightstep.configureOpenTelemetry({ | |
| accessToken: '<ACCESS_TOKEN>', | |
| serviceName: 'hello-server-1', | |
| serviceVersion: 'v1.2.3', | |
| propagators: 'tracecontext,b3', | |
| }); | |
| sdk.start().then(() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const opentelemetry = require('@opentelemetry/api'); | |
| const express = require('express'); | |
| // create a tracer and name it after your package | |
| const tracer = opentelemetry.trace.getTracer('@otel-node-basics/server'); | |
| const app = express(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const app = express(); | |
| app.get('/hello', (req, res) => { | |
| // access the span created by express instrumentation | |
| span = tracer.getCurrentSpan(); | |
| // add an attribute to segment your data by projectID | |
| span.setAttribute('projectID', '123'); | |
| // log an event and include some structured data. | |
| span.addEvent('setting timeout', { sleep: 300 }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.get('/hello', (req, res) => { | |
| tracer.getCurrentSpan() | |
| .setAttribute('projectID', '123') | |
| .addEvent('setting timeout', { sleep: 300 }); | |
| setTimeout(()=> { | |
| tracer.getCurrentSpan().addEvent('sending response'); | |
| res.status(200).send('Hello World'); | |
| }, 300); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.get('/hello', (req, res) => { | |
| // start a new span named “sleeper” | |
| const childSpan = tracer.startSpan("sleeper"); | |
| setTimeout(()=> { | |
| // childSpan works normally when referenced | |
| childSpan.addEvent('finished sleeping'); | |
| // However, starting a span does not automatically | |
| // set it to the current span. getCurrentSpan still | |
| // returns the parent span. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.get('/hello', (req, res) => { | |
| // start a new span named “sleeper” | |
| const childSpan = tracer.startSpan("sleeper"); | |
| // use withSpan to create a new context | |
| tracer.withSpan(childSpan,()=> { | |
| setTimeout(()=> { | |
| // getCurrentSpan now correctly returns childSpan | |
| const span = tracer.getCurrentSpan(); | |
| span.addEvent('sending response'); |