Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support standard OTEL exporter protocol environment variables #63

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package otel

import (
"fmt"
"os"

"github.com/google/uuid"
"go.uber.org/zap"
Expand Down Expand Up @@ -78,9 +79,13 @@ func (c *Config) InitDefault(log *zap.Logger) {
}

switch c.Client {
case grpcClient:
case httpClient:
case grpcClient, httpClient:
// ok value, do nothing
case "":
c.Client = httpClient
setClientFromEnv(&c.Client, log)
default:
log.Warn("unknown exporter client", zap.String("client", string(c.Client)))
c.Client = httpClient
}

Expand Down Expand Up @@ -112,3 +117,25 @@ func (c *Config) InitDefault(log *zap.Logger) {
c.Resource.ServiceNamespaceKey = fmt.Sprintf("RoadRunner-%s", uuid.NewString())
}
}

func setClientFromEnv(client *Client, log *zap.Logger) {
// https://opentelemetry.io/docs/specs/otel/protocol/exporter/#specify-protocol
exporterEnv := "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL"
exporterVal := os.Getenv(exporterEnv)
if exporterVal == "" {
exporterEnv = "OTEL_EXPORTER_OTLP_PROTOCOL"
exporterVal = os.Getenv(exporterEnv)
}
switch exporterVal {
case "":
// env var not set, do not change the client
case "grpc":
*client = grpcClient
case "http/protobuf":
*client = httpClient
case "http/json":
log.Warn("unsupported exporter protocol", zap.String("env.name", exporterEnv), zap.String("env.value", exporterVal))
default:
log.Warn("unknown exporter protocol", zap.String("env.name", exporterEnv), zap.String("env.value", exporterVal))
}
}
Loading