Skip to content

Instantly share code, notes, and snippets.

View tedsuo's full-sized avatar

Ted Young tedsuo

View GitHub Profile
@tedsuo
tedsuo / otel_laucher_go_example.go
Last active September 29, 2020 02:33
OTel Launcher Go Example
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()
}
@tedsuo
tedsuo / otel_example.go
Created September 29, 2020 03:09
OTel Go current LS setup
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(
@tedsuo
tedsuo / node_basic_server.js
Created November 11, 2020 21:48
node_basic_server.js
const express = require('express');
const app = express();
app.get('/hello', (req, res) => {
res.status(200).send('Hello World');
});
app.listen(9000);
@tedsuo
tedsuo / node_basic_client.js
Created November 11, 2020 21:48
node_basic_client.js
const http = require('http');
function makeRequest() {
http.get({
host: 'localhost',
port: 9000,
path: '/hello',
}, (response) => {
const body = [];
response.on('data', (chunk) => body.push(chunk));
@tedsuo
tedsuo / node_server_init.js
Created November 11, 2020 23:07
node_server_init.js
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(() => {
@tedsuo
tedsuo / node_create_tracer.js
Created November 11, 2020 23:08
node_create_tracer.js
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();
@tedsuo
tedsuo / node_span_basics.js
Created November 11, 2020 23:09
node_span_basics.js
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 });
@tedsuo
tedsuo / node_span_chaining.js
Created November 11, 2020 23:09
node_span_chaining.js
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);
});
@tedsuo
tedsuo / node_span_start.js
Created November 11, 2020 23:21
node_span_start.js
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.
@tedsuo
tedsuo / node_with_span.js
Created November 11, 2020 23:25
node_with_span.js
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');