Setup and Install OpenTelemetry Go

Get up and running with OpenTelemetry in just a few quick steps! The setup process consists of two phases--getting OpenTelemetry installed and configured, and then validating that configuration to ensure that data is being sent as expected. This guide explains how to download, install, and run OpenTelemetry in Go.

Requirements

  • Go version 1.13 or newer
  • An app to add OpenTelemetry to. You can use this example application or bring your own.
  • A Lightstep account, or another OpenTelemetry backend.

Need an account? Create a free Lightstep account here.

Installation

To install OpenTelemetry, we recommend our handy OTel-Launcher, which simplifies the process.

go get "github.com/lightstep/otel-launcher-go/launcher"

Run OpenTelemetry

Once you've downloaded the launcher, you can run OpenTelemetry using the following basic configuration.

LS Note: When connecting to Lightstep, a project Access Token is required.

The full list of configuration options can be found in the README.

import "github.com/lightstep/otel-launcher-go/launcher"

func main() {
   otel := launcher.ConfigureOpentelemetry(
       launcher.WithServiceName("service-123"),
       launcher.WithAccessToken("<ACCESS TOKEN>"),
   )
   defer otel.Shutdown()
}

Validate Installation

With your application running, you can now verify that you’ve installed OpenTelemetry correctly by confirming that telemetry data is being reported to your observability backend.

To do this, you need to make sure that your application is actually generating data. Applications will generally not produce traces unless they are being interacted with, and opentelemetry will often buffer data before sending it. So it may take some amount of time and interaction before your application data begins to appear in your backend.

Validate your traces in Lightstep:

  1. Trigger an action in your app that generates a web request.
  2. In Lightstep, click on the Explorer in the sidebar.
  3. Refresh your query until you see traces.
  4. View the traces and verify that important aspects of your application are captured by the trace data.

Library and Framework Support

Besides OpenTelemetry core modules, it is important to install instrumentation packages for every important library and framework which your service depends upon. Beyond the critical telemetry data these components emit, library and framework integrations are often required to ensure that the trace context is properly propagated.

OpenTelemetry automatically provides instrumentation for a large number of libraries and frameworks, right out of the box.

The full list of supported instrumentation can be found in the README.

Don’t see support for a framework or library you use? Join the beta by filing an issue, or try your hand at writing an instrumentation adapter yourself!

OpenTracing Support

The OpenTracing shim allows existing OpenTracing instrumentation to report to the OpenTelemetry SDK. OpenTracing support is not enabled by default. Instructions for enabling the shim can be found in the README.

Read more about upgrading to OpenTelemetry in our OpenTracing Migration Guide.

Run the launcher in debug mode

If spans are not being reported to Lightstep, try running in debug mode by setting OTEL_LOG_LEVEL=debug:

OTEL_LOG_LEVEL=debug node first-tracer.js

The debug log level will print out the configuration information. Check to ensure that your access token looks correct. It will also emit every span to the console, which should look something like:

Span {
  attributes: {},
  links: [],
  events: [],
  status: { code: 0 },
  endTime: [ 1597810686, 885498645 ],
  _ended: true,
  _duration: [ 0, 43333 ],
  name: 'bar',
  spanContext: {
    traceId: 'eca3cc297720bd705e734f4941bca45a',
    spanId: '891016e5f8c134ad',
    traceFlags: 1,
    traceState: undefined
  },
  parentSpanId: 'cff3a2c6bfd4bbef',
  kind: 0,
  startTime: [ 1597810686, 885455312 ],
  resource: Resource { labels: [Object] },
  instrumentationLibrary: { name: 'example', version: '*' },
  _logger: ConsoleLogger {
    debug: [Function],
    info: [Function],
    warn: [Function],
    error: [Function]
  },
  _traceParams: {
    numberOfAttributesPerSpan: 32,
    numberOfLinksPerSpan: 32,
    numberOfEventsPerSpan: 128
  },
  _spanProcessor: MultiSpanProcessor { _spanProcessors: [Array] }
},