package otlptraces
Import Path
go.pact.im/x/traces/otlptraces (on go.dev)
Dependency Relation
imports 14 packages, and imported by one package
Involved Source Files
Package otlptraces implements an OTLP/HTTP protobuf trace exporter using
[net/http].
encode.go
error.go
exporter.go
Code Examples
package main
import (
"context"
"errors"
"net/http"
"time"
"go.pact.im/x/traces"
"go.pact.im/x/traces/batchtraces"
"go.pact.im/x/traces/otlptraces"
)
func main() {
exp := &otlptraces.Exporter{
Client: &http.Client{Timeout: 10 * time.Second},
Endpoint: otlptraces.DefaultEndpoint,
Resource: []traces.Attr{
traces.String("service.name", "users"),
},
}
withRetry := batchtraces.ExporterFunc(func(ctx context.Context, batch []traces.Record) error {
var err error
for attempt := range 3 {
err = exp.Export(ctx, batch)
if err == nil {
return nil
}
if herr, ok := errors.AsType[*otlptraces.HTTPError](err); ok && !herr.Retryable() {
return err
}
if attempt == 2 {
break
}
}
return err
})
batcher := batchtraces.NewBatcher(withRetry, batchtraces.Options{})
tr := traces.New(batcher).WithSampler(traces.ParentBased(traces.Ratio(0.1)))
_ = tr
}
Package-Level Type Names (total 3, in which 2 are exported)
Exporter sends span batches to an OTLP/HTTP traces endpoint using protobuf
encoding. It is stateless and safe for concurrent use.
Each [Exporter.Export] call performs a single HTTP POST request; compose
retries and batching around Exporter as needed.
Client specifies the HTTP client to use.
Defaults to [httpclient.DefaultClient].
DisableGzip disables gzip compression of the OTLP protobuf request body.
By default, request bodies are gzip-compressed with Content-Encoding: gzip.
Endpoint is the full OTLP/HTTP traces URL.
Defaults to [DefaultEndpoint].
Header specifies additional HTTP headers added to every request
(such as Authorization or api-key).
Resource specifies resource attributes describing the process
producing the spans (such as service.name and service.version).
SchemaURL optionally specifies the OpenTelemetry semantic conventions
schema URL attached to exported ResourceSpans and ScopeSpans.
Export encodes batch as OTLP protobuf and POSTs it once to
[Exporter.Endpoint]. An empty batch is a no-op and returns nil.
(*Exporter) encode(batch []traces.Record) *tracepb.TracesData
*Exporter : go.pact.im/x/traces/batchtraces.Exporter
HTTPError is returned by [Exporter.Export] when the collector responds with a
non-2xx HTTP status code.
Body is a prefix of the response body (up to 4 KiB).
Header is the HTTP response header.
StatusCode is the HTTP response status code.
Error implements the error interface.
RetryAfter parses the Retry-After response header relative to now.
It returns 0 if the header is absent, invalid, or not in the future.
Retryable reports whether the OTLP specification permits retrying the
request (429, 502, 503, 504).
*HTTPError : error
Package-Level Functions (total 2, neither is exported)
Package-Level Constants (total 10, in which 1 is exported)
DefaultEndpoint is the default OTLP/HTTP traces endpoint URL.
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64)