arizeotel

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

README

arize-otel-go

Go helper for sending OpenTelemetry traces to Arize. Wraps the standard OTel OTLP/HTTP setup with Arize-aware defaults so you don't hand-roll ~30 lines of tracer-provider boilerplate on every service.

Go equivalent of arize-otel-python.

Install

go get github.com/Arize-ai/arize-otel-go

Requires Go 1.23+.

Quick start

package main

import (
    "context"
    "log"
    "time"

    "go.opentelemetry.io/otel"
    "go.opentelemetry.io/otel/attribute"

    arizeotel "github.com/Arize-ai/arize-otel-go"
)

func main() {
    ctx := context.Background()

    tp, err := arizeotel.Register(ctx, arizeotel.Options{
        ProjectName: "my-go-service",
        // SpaceID and APIKey default to $ARIZE_SPACE_ID and $ARIZE_API_KEY.
    })
    if err != nil {
        log.Printf("register tracer: %v", err)
        return
    }
    defer func() {
        shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
        defer cancel()
        _ = tp.Shutdown(shutdownCtx)
    }()

    tracer := otel.Tracer("my-app")
    _, span := tracer.Start(ctx, "hello")
    span.SetAttributes(attribute.String("input.value", "hi"))
    span.End()
}

Critical for short-lived processes: never call log.Fatalf or os.Exit after a span has started — they skip the deferred tp.Shutdown(ctx) and the in-flight spans never flush. Use log.Printf + return from main instead.

Options

Field Default Description
SpaceID $ARIZE_SPACE_ID Arize Space ID. Required.
APIKey $ARIZE_API_KEY Arize API key. Required.
ProjectName $ARIZE_PROJECT_NAME or "default" Sets the openinference.project.name resource attribute.
Endpoint $ARIZE_COLLECTOR_ENDPOINT or otlp.arize.com OTLP/HTTP collector hostname. Use arizeotel.EndpointArizeEurope for EU spaces. Accepts bare host or full URL.
ExtraHeaders none Merged into the OTLP request headers alongside the required space_id / api_key headers.
ExtraResourceAttributes none Appended to the OTel Resource. Common: attribute.String("deployment.environment", "prod").
Insecure false Disables TLS. Only set for on-prem / local collectors.
SimpleProcessor false (batched) Use SimpleSpanProcessor instead of Batched. Useful for tests and short CLIs.
SkipSetGlobal false Skip calling otel.SetTracerProvider. Set if you manage the global provider yourself.

EU spaces

arizeotel.Register(ctx, arizeotel.Options{
    Endpoint: arizeotel.EndpointArizeEurope,
})

Pairs with OpenInference Go

Combine with openinference-go/semconv for typed attribute-key constants:

import "github.com/Arize-ai/openinference/go/semconv"

span.SetAttributes(
    attribute.String(semconv.OpenInferenceSpanKind, semconv.SpanKindLLM),
    attribute.String(semconv.LLMModelName, "gpt-4o"),
)

Examples

  • examples/manual — minimal CHAIN + LLM span, no LLM SDK dependency. Run with ARIZE_SPACE_ID=… ARIZE_API_KEY=… go run ./examples/manual.

Status

v0.1.0 — initial release. API may evolve; pin a tag.

License

BSD-3-Clause (matches arize-otel-python and the rest of the Arize SDK family).

Documentation

Overview

Package arizeotel is the Go helper for sending OpenTelemetry traces to Arize. It wraps the standard OTel OTLP/HTTP setup with Arize-aware defaults so callers don't have to hand-roll ~30 lines of tracer-provider boilerplate on every service.

Typical usage:

tp, err := arizeotel.Register(ctx, arizeotel.Options{
    ProjectName: "my-go-service",
    // SpaceID and APIKey default to $ARIZE_SPACE_ID and $ARIZE_API_KEY.
})
if err != nil {
    log.Printf("arize tracer: %v", err)
    return
}
defer tp.Shutdown(ctx)

After Register returns, otel.Tracer("…") yields tracers wired to Arize. Never call log.Fatalf after a span has started — it skips the deferred Shutdown and the in-flight spans never flush.

This is the Go equivalent of arize-otel-python's register().

Index

Constants

View Source
const (
	EndpointArize       = "otlp.arize.com"
	EndpointArizeEurope = "otlp.eu-west-1a.arize.com"
)

Default Arize OTLP/HTTP endpoint hostnames. The OTLP HTTP exporter takes a bare hostname (no scheme, no path) via WithEndpoint.

View Source
const (
	EnvSpaceID     = "ARIZE_SPACE_ID"
	EnvAPIKey      = "ARIZE_API_KEY"
	EnvProjectName = "ARIZE_PROJECT_NAME"
	EnvEndpoint    = "ARIZE_COLLECTOR_ENDPOINT"
)

Environment variable names recognised by Register.

View Source
const Version = "0.1.0"

Version is the package version reported as the service.version resource attribute on every span created by tracers from a Register-returned TracerProvider.

Variables

This section is empty.

Functions

func Register

func Register(ctx context.Context, opts Options) (*sdktrace.TracerProvider, error)

Register configures an OpenTelemetry TracerProvider that exports spans to Arize via OTLP/HTTP, registers it as the global TracerProvider, and returns it so the caller can defer tp.Shutdown(ctx) to flush buffered spans before exit.

Callers should ALWAYS defer tp.Shutdown — for CLI/script processes, dropping this defer means batched spans never flush and traces never appear in Arize.

Types

type Options

type Options struct {
	// SpaceID is the Arize Space ID. Required (via field or $ARIZE_SPACE_ID).
	SpaceID string
	// APIKey is the Arize API key. Required (via field or $ARIZE_API_KEY).
	APIKey string
	// ProjectName is the project to associate spans with. Defaults to
	// "default" if empty and $ARIZE_PROJECT_NAME is unset.
	ProjectName string
	// Endpoint is the Arize OTLP/HTTP collector hostname. Defaults to
	// EndpointArize (US). Use EndpointArizeEurope for EU spaces. Accepts
	// either a bare hostname ("otlp.arize.com") or a full URL
	// ("https://otlp.arize.com") — the scheme and path are stripped.
	Endpoint string
	// ExtraHeaders are merged into the OTLP/HTTP request headers alongside
	// the required space_id and api_key headers. Use this to set custom
	// routing headers or for on-prem deployments.
	ExtraHeaders map[string]string
	// ExtraResourceAttributes are merged into the OTel Resource alongside
	// the required project-name attribute. Common additions: deployment
	// environment, host metadata, build SHA. Values provided here override
	// the defaults Register sets for service.name and service.version.
	ExtraResourceAttributes []attribute.KeyValue
	// Insecure disables TLS on the OTLP/HTTP exporter. Default false. Only
	// set true for on-prem or local collectors.
	Insecure bool
	// SimpleProcessor uses SimpleSpanProcessor instead of BatchSpanProcessor.
	// Default false (batched). Useful for tests and CLIs where you want
	// every span flushed immediately.
	SimpleProcessor bool
	// SkipSetGlobal omits calling otel.SetTracerProvider on the returned
	// TracerProvider. Default false (the provider becomes the global one).
	SkipSetGlobal bool
}

Options configure the Register call. Empty string fields fall back to the matching ARIZE_* environment variable (and then to documented defaults).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL