OpenTelemetry Integration for Go Applications
The main approach for integrating with OpenTelemetry is to configure the default OTLP exporter of any application that is monitored by OpenTelemetry to send its data to the Instana agent. This is described on the OpenTelemetry page.
Serverless OpenTelemetry Exporter
The module github.com/instana/go-otel-exporter offers an OpenTelemetry exporter that converts and sends OpenTelemetry spans to the Instana back end.
The Instana Go OpenTelemetry exporter is designed primarily for usage in serverless environments, such as AWS Lambda or AWS Fargate. Instana already provides support for OpenTelemetry for SaaS and self hosted solutions through the host agent. However, if your Go applications run in a serverless environment, where the agent is not present, the serverless OpenTelemetry exporter is the way to go.
To use the exporter, install the module into your project, create a new instance of the exporter with instana.New()
and add it to the Tracer Provider.
The exporter expects two Instana environment variables that must be provided to the application:
INSTANA_AGENT_KEY
INSTANA_ENDPOINT_URL
A full usage example of the exporter is described as follows:
package main
import (
"context"
"time"
instana "github.com/instana/go-otel-exporter"
"go.opentelemetry.io/otel"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
)
// This example application demonstrates how to use the Instana OTel Exporter.
// Make sure to provide the required environment variables before run the application:
// * INSTANA_ENDPOINT_URL
// * INSTANA_AGENT_KEY
func main() {
ch := make(chan bool)
// Acquire an instance of the Instana OTel Exporter
exporter := instana.New()
// Setup and bootstrap the tracer provider
tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exporter),
)
otel.SetTracerProvider(tracerProvider)
ctx := context.Background()
// Instrument something with OTel
tracer := otel.Tracer("my-traced-tech")
_, span := tracer.Start(ctx, "my_span", trace.WithSpanKind(trace.SpanKindServer))
// This simulates the time that a span takes to be completed
time.Sleep(time.Millisecond * 400)
span.End()
<-ch
}
When the application that is monitored by OpenTelemetry runs, the Instana exporter will convert the OpenTelemetry spans to Instana spans, and send them to the back end endpoint.
The OpenTelemetry trace visualization will be present in the Instana UI, like regular Instana tracing spans.