---
title: "Send OpenTelemetry from Go to your Mac"
description: "Wire the OTLP exporter in main.go, wrap your HTTP handler with otelhttp, and read the traces of your Go service in one window."
source: "https://getloggerhead.com/docs/send-telemetry/go/"
---

# Send OpenTelemetry from Go to your Mac

> Wire the OTLP exporter in main.go, wrap your HTTP handler with otelhttp, and read the traces of your Go service in one window.

Go has no automatic instrumentation. You start the SDK yourself, in about twenty lines, and wrap the handlers you care about.

## Before you start

- Loggerhead is open.
- You know the effective port. Open **Collectors → Loggerhead receiver → Connection** and copy the HTTP port. The first workspace uses 4318. See [Ports and the effective port](/docs/getting-started/ports-and-the-effective-port/).

## Step 1: get the packages

```bash
go get go.opentelemetry.io/otel \
  go.opentelemetry.io/otel/sdk \
  go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp \
  go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp
```

## Step 2: start the tracer provider

```go title="main.go"
func startTracing(ctx context.Context) (func(context.Context) error, error) {
	exporter, err := otlptracehttp.New(ctx)
	if err != nil {
		return nil, err
	}
	res, err := resource.New(ctx,
		resource.WithAttributes(semconv.ServiceName("my-go-service")),
	)
	if err != nil {
		return nil, err
	}
	tp := trace.NewTracerProvider(
		trace.WithBatcher(exporter),
		trace.WithResource(res),
	)
	otel.SetTracerProvider(tp)
	return tp.Shutdown, nil
}
```

`otlptracehttp.New` reads `OTEL_EXPORTER_OTLP_ENDPOINT`, so the address stays out of the code.

## Step 3: wrap the handler

```go
mux := http.NewServeMux()
mux.Handle("/orders", ordersHandler)
http.ListenAndServe(":8080", otelhttp.NewHandler(mux, "http"))
```

## Step 4: set the endpoint

```bash
export OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318
```

Run the service and call one route.

## What arrives

| Signal | State |
| --- | --- |
| Traces | Every handler you wrap, and every client call you instrument. |
| Metrics | Add the metric SDK and `otlpmetrichttp` the same way. |
| Logs | Add `otelslog` to bridge `log/slog`, or send the output through a branch collector. |

## Tag the environment

```bash
export OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=staging
```

See [Workspaces and environments](/docs/getting-started/workspaces-and-environments/).

## Then read it with your agent

1. Open **Traces** in Loggerhead and click a request to open its waterfall.
2. Connect your coding agent once, and it reads the same data. See [Claude Code](/docs/connect-your-ai-tool/claude-code/).
