Ingest logs from Go (Papertrail)
You can ship Go application logs directly to SolarWinds Papertrail with OpenTelemetry (OTLP). The application keeps logging with the standard log/slog package. The official OpenTelemetry Go SDK and its otelslog bridge send every record to the OTLP endpoint. No custom code is needed. Each log record will do the following:
- Show the correct System, Program, and Severity in the Logs Explorer.
- Keep the log message as written, where every slog attribute is a separate searchable field.
- Arrive as one event even when the message spans several lines.
- Be sent in batches over port 443 from a background goroutine, so logging never waits for the network.
To get a destination and token in Papertrail, add a new log destination. The ingestion token is generated along with the destination. Use the collector endpoint for your account's region:
-
OTLP:
https://otel.collector.<REGION>.cloud.solarwinds.com/v1/logs
Replace <REGION> with the data center your organization uses: na-01, eu-01, or ap-01.
How Papertrail fills System, Program, and Severity
The Papertrail Logs Explorer is syslog-shaped. It shows the source in the System column, the application in the Program column, and the Severity of each event. For OTLP, the collector reads them from the resource attributes and from each log record:
| Logs Explorer value | Source | Go value |
|---|---|---|
| System | host.name resource attribute |
Host name ( In a container, the container ID, unless you set the host name. |
| Program | service.name resource attribute |
OTEL_SERVICE_NAME
|
| Severity | severityNumber
|
slog level:
|
| Message | Log record body | The slog message |
| Searchable attributes | Log record attributes | Each slog attribute under its own name, for example, order_id:1234 |
Message and attributes
The message stays as written, so it reads well in the Logs Explorer. The attributes are not added to the message text but remain as separate fields. This allows tools and AI agents to filter on them exactly.
| Code | Message | Searchable as |
|---|---|---|
slog.Info("Order processed", "order_id", 1234)
|
Order processed
|
order_id:1234
|
slog.Warn("Slow query", slog.Group("db", "table", "orders"))
|
Slow query
|
db.table:orders
|
slog.Error("Payment failed", "err", err)
|
Payment failed
|
exception.message, exception.type |
slog.Info("Done", "duration", 42*time.Millisecond)
|
Done
|
duration:42000000 (in nanoseconds) |
Requirements
-
Go 1.26 or later. The current OpenTelemetry Go release supports the two newest Go versions.
-
Outbound HTTPS (port 443) to
otel.collector.<REGION>.cloud.solarwinds.comReplace<REGION>with the data center your organization uses:na-01,eu-01, orap-01.
The instructions below were tested with go.opentelemetry.io/otel v1.47.0, otel/sdk/log v1.47.0, otlploghttp v0.23.0 and otelslog v0.21.0.
Step 1: Add the modules
Run the following command from the root of your Go module (the directory that contains go.mod) to add the OpenTelemetry packages your application needs to send logs.
go get go.opentelemetry.io/otel go.opentelemetry.io/otel/sdk go.opentelemetry.io/otel/sdk/log go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp go.opentelemetry.io/contrib/bridges/otelslog
Step 2: Set up logging in main
Add the following at the start of main, and merge the imports with your existing ones:
import (
"context"
"fmt"
"log"
"log/slog"
"os"
"go.opentelemetry.io/contrib/bridges/otelslog"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp"
sdklog "go.opentelemetry.io/otel/sdk/log"
"go.opentelemetry.io/otel/sdk/resource"
)
func main() {
ctx := context.Background()
// Print delivery errors (wrong token, network) to stderr, not into the log pipeline itself.
otel.SetErrorHandler(otel.ErrorHandlerFunc(func(err error) { fmt.Fprintln(os.Stderr, "log export:", err) }))
// Endpoint and token from OTEL_EXPORTER_OTLP_LOGS_ENDPOINT and OTEL_EXPORTER_OTLP_LOGS_HEADERS.
exporter, err := otlploghttp.New(ctx)
if err != nil {
log.Fatal(err)
}
// System = host name, Program = OTEL_SERVICE_NAME.
res, err := resource.New(ctx, resource.WithHost(), resource.WithFromEnv())
if err != nil {
log.Fatal(err)
}
provider := sdklog.NewLoggerProvider(
sdklog.WithResource(res),
sdklog.WithProcessor(sdklog.NewBatchProcessor(exporter)),
)
defer func() { // send the last batch before main returns
if err := provider.Shutdown(ctx); err != nil {
fmt.Fprintln(os.Stderr, "log export:", err)
}
}()
slog.SetDefault(otelslog.NewLogger("app", otelslog.WithLoggerProvider(provider)))
// ... rest of main
}
Notes
-
Keep the error handler and the
Shutdowncheck. Without them, a wrong token or an unreachable endpoint fails silently, because the SDK would report its errors through the logging pipeline that just failed. -
slog.SetDefaultalso routes the standard log package (log.Printf) through OpenTelemetry at level Info. All levels are sent, including Debug. -
A deferred function does not run on
os.Exitorlog.Fatal. Callprovider.Shutdown(ctx)before those, otherwise the last batch is lost. -
net/httpreports handler panics through the server's error log. SetErrorLog: slog.NewLogLogger(slog.Default().Handler(), slog.LevelError) on yourhttp.Serverto receive them as error records. -
Stack traces logged as an attribute (
"stack", string(debug.Stack())) are searchable but not shown in the message. To read them in the Logs Explorer, append them to the message instead. Multi-line messages stay a single event.
Step 3: Set the environment variables
Set the following variables in the environment where your application runs, then restart the application so it picks them up:
OTEL_SERVICE_NAME=my-service OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://otel.collector.<REGION>.cloud.solarwinds.com/v1/logs OTEL_EXPORTER_OTLP_LOGS_HEADERS=authorization=Bearer%20<TOKEN>
<REGION> with the data center your organization uses: na-01, eu-01, or ap-01. Notes
-
Write the space after
Beareras%20. -
OTEL_SERVICE_NAMEbecomes the Program. -
Keep the token out of source control. Use your container environment, systemd unit, Kubernetes Secret or CI/CD secret store.
Step 4: Verify
Add the following temporarily in place of // ... rest of main (add the imports errors, runtime/debug, and time), and run the program until it exits normally:
m := "swo-setup-check-" + time.Now().UTC().Format("20060102150405")
slog.Info("Hello from Go "+m, "order_id", 1234)
slog.Error("Payment failed "+m, "err", errors.New("card declined"), "stack", string(debug.Stack()))
fmt.Println("marker:", m)
In the Logs Explorer, search for the printed marker. The System column shows your host name, Program shows OTEL_SERVICE_NAME, and the second record has severity ERROR. <marker> order_id:1234 finds the first record.
What arrives in the Logs Explorer
Search attributes of each event are displayed in the Logs Explorer:
| Attribute | Value |
|---|---|
host.name, service.name |
System and Program |
Attribute names, for example order_id |
Each slog attribute, groups as |
exception.message, exception.type |
An error value logged as an attribute |
Troubleshooting
| Symptom | Likely cause | What to do |
|---|---|---|
log export: ... 401 Unauthorized on stderr |
Wrong token, or the token belongs to a different region | Copy the token again from the log destination and check the region in OTEL_EXPORTER_OTLP_LOGS_ENDPOINT. |
log export: ... no such host
|
Wrong region in the endpoint | Use na-01, eu-01, or ap-01. |
log export: Post "https://localhost:4318/v1/logs" ...
|
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT is not set in the process |
Set the variables where the application runs. |
| Program is empty | OTEL_SERVICE_NAME is not set |
Set OTEL_SERVICE_NAME |
| A short-lived program sends nothing and prints nothing | Shutdown did not run (os.Exit, log.Fatal, or the process was killed) |
Call provider.Shutdown(ctx) before every exit path. |
Fallback: Forward via a syslog daemon
If your application cannot connect directly to the Papertrail collector — for example, a strict outbound firewall blocks port 443 — write logs to a local file and use the host's syslog daemon to forward them to Papertrail over TLS. SolarWinds Observability supports rsyslog on Linux and NXlog on Windows for this purpose. See Send Logs using syslog for configuration instructions.
The scripts are not supported under any SolarWinds support program or service. The scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.