This exporter exports OpenTelemetry spans and metrics to the OpenTelemetry Collector.
The exporter can be installed using standard go
functionality.
$ go get -u go.opentelemetry.io/otel/exporters/otlp
A new exporter can be created using the NewExporter
function.
package main
import (
"log"
"go.opentelemetry.io/otel/exporters/otlp"
"go.opentelemetry.io/otel/sdk/metric/controller/push"
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
func main() {
exporter, err := otlp.NewExporter() // Configure as needed.
if err != nil {
log.Fatalf("failed to create exporter: %v", err)
}
defer func() {
err := exporter.Stop()
if err != nil {
log.Fatalf("failed to stop exporter: %v", err)
}
}()
// Note: The exporter can also be used as a Batcher. E.g.
// tracerProvider := sdktrace.NewProvider(
// sdktrace.WithBatcher(exporter,
// sdktrace.WithBatchTimeout(time.Second*15),
// sdktrace.WithMaxExportBatchSize(100),
// ),
// )
tracerProvider := sdktrace.NewProvider(sdktrace.WithBatcher(exporter))
pusher := push.New(simple.NewWithExactDistribution(), exporter)
pusher.Start()
metricProvider := pusher.Provider()
// Your code here ...
}
Configurations options can be specified when creating a new exporter (NewExporter
).
Sets the number of Goroutines to use when processing telemetry.
Disables client transport security for the exporter's gRPC connection just like grpc.WithInsecure()
does.
By default, client security is required unless WithInsecure
is used.
Sets the address that the exporter will connect to the collector on.
The default address the exporter connects to is localhost:55680
.
Set the delay between connection attempts after failing to connect with the collector.
Set the compressor for the gRPC client to use when sending requests.
The compressor used needs to have been registered with google.golang.org/grpc/encoding
prior to using here.
This can be done by encoding.RegisterCompressor
.
Some compressors auto-register on import, such as gzip, which can be registered by calling import _ "google.golang.org/grpc/encoding/gzip"
.
Headers to send with gRPC requests.
TLS credentials to use when talking to the server.
The default gRPC service config used when .
By default, the exporter is configured to support retries.
{
"methodConfig":[{
"name":[
{ "service":"opentelemetry.proto.collector.metrics.v1.MetricsService" },
{ "service":"opentelemetry.proto.collector.trace.v1.TraceService" }
],
"waitForReady": true,
"retryPolicy":{
"MaxAttempts":5,
"InitialBackoff":"0.3s",
"MaxBackoff":"5s",
"BackoffMultiplier":2,
"RetryableStatusCodes":[
"UNAVAILABLE",
"CANCELLED",
"DEADLINE_EXCEEDED",
"RESOURCE_EXHAUSTED",
"ABORTED",
"OUT_OF_RANGE",
"UNAVAILABLE",
"DATA_LOSS"
]
}
}]
}
Additional grpc.DialOption
to be used.
These options take precedence over any other set by other parts of the configuration.
The exporter will not, by default, retry failed requests to the collector. However, it is configured in a way that it can easily be enable.
To enable retries, the GRPC_GO_RETRY
environment variable needs to be set to on
. For example,
GRPC_GO_RETRY=on go run .
The default service config used by default is defined to retry failed requests with exponential backoff (0.3seconds * (2)^retry
) with a max of 5
retries).
These retries are only attempted for reponses that are deemed "retry-able" by the collector.