Skip to content

Commit

Permalink
[#63]: feature: support standard OTEL exporter protocol environment…
Browse files Browse the repository at this point in the history
… variables
  • Loading branch information
rustatian authored Aug 30, 2024
2 parents 36f2357 + a17f4eb commit dc7a816
Showing 1 changed file with 29 additions and 2 deletions.
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))
}
}

0 comments on commit dc7a816

Please sign in to comment.