OpenTelemetry for Go

OpenTelemetry offers flexible APIs and SDKs for instrumenting Go applications. With lightweight libraries, you can capture traces, logs, and metrics without adding unnecessary overhead.

Installation

Install the necessary OpenTelemetry Go modules:

go get go.opentelemetry.io/otel
go get go.opentelemetry.io/otel/sdk
go get go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp

For full installation instructions:
👉 OpenTelemetry Go Getting Started

Auto-Instrumentation

Auto-instrumentation lets you automatically trace common libraries such as HTTP clients, database drivers, and more without needing to modify your code. OpenTelemetry provides auto-instrumentation libraries for many popular languages, making it fast to get started with tracing.

Go favors manual instrumentation first, but several libraries offer automatic instrumentation wrappers (e.g., gRPC, HTTP).

Learn more:
👉 Go Instrumentation Libraries

Manual Instrumentation

Manual instrumentation gives you full control over your traces, allowing you to create spans wherever needed. You can customize span names, attributes, and relationships to capture the most important parts of your application’s flow.

You can create spans directly in your Go code:

import ( "context" "go.opentelemetry.io/otel" )
tracer := otel.Tracer("my-service")
ctx, span := tracer.Start(context.Background(), "my-operation") // your application logic
span.End()

Learn more:
👉 Go Manual Instrumentation Guide

Exporters

Once your application is instrumented, you need to export telemetry data. PlayerZero supports the OpenTelemetry Protocol (OTLP) over HTTP. You can configure your OpenTelemetry SDK to export traces, logs, and metrics to PlayerZero’s endpoint by setting the endpoint URL and API token.

In Go, you typically configure OTLP exporters programmatically when initializing your SDK.

Key properties to set:

Endpoint: https://sdk.playerzero.app/otlp 
Headers: Authorization=Bearer <your-playerzero-token>

Official reference:
👉 Go SDK Configuration

Optional: Using a Collector

Using an OpenTelemetry Collector is optional for most setups. A collector can help route telemetry to multiple destinations, perform transformations, or batch data efficiently. You might use a collector if you want to forward telemetry to both PlayerZero and another observability platform simultaneously.

You can also send data to a local or remote OpenTelemetry Collector for more flexible data handling before forwarding to PlayerZero.

For detailed language-specific instrumentation examples and full OpenTelemetry documentation, refer to the links below.