Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Changed

- Updated Jaeger Environment Variables (#1639)
Comment thread
MrAlias marked this conversation as resolved.
Outdated
- Jaeger exporter was updated to use thrift v0.14.1. (#1712)
- Migrate from using internally built and maintained version of the OTLP to the one hosted at `go.opentelemetry.io/proto/otlp`. (#1713)
- Migrate from using `github.com/gogo/protobuf` to `google.golang.org/protobuf` to match `go.opentelemetry.io/proto/otlp`. (#1713)
Expand Down
108 changes: 4 additions & 104 deletions exporters/trace/jaeger/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,21 @@
package jaeger // import "go.opentelemetry.io/otel/exporters/trace/jaeger"

import (
"errors"
"os"
"strconv"
"strings"

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

// Environment variable names
const (
// The service name.
envServiceName = "JAEGER_SERVICE_NAME"
// Whether the exporter is disabled or not. (default false).
envDisabled = "JAEGER_DISABLED"
// A comma separated list of name=value tracer-level tags, which get added to all reported spans.
// The value can also refer to an environment variable using the format ${envVarName:defaultValue}.
envTags = "JAEGER_TAGS"
envDisabled = "OTEL_EXPORTER_JAEGER_DISABLED"
Comment thread
MrAlias marked this conversation as resolved.
Outdated
// The HTTP endpoint for sending spans directly to a collector,
// i.e. http://jaeger-collector:14268/api/traces.
envEndpoint = "JAEGER_ENDPOINT"
envEndpoint = "OTEL_EXPORTER_JAEGER_ENDPOINT"
// Username to send as part of "Basic" authentication to the collector endpoint.
envUser = "JAEGER_USER"
envUser = "OTEL_EXPORTER_JAEGER_USER"
// Password to send as part of "Basic" authentication to the collector endpoint.
envPassword = "JAEGER_PASSWORD"
envPassword = "OTEL_EXPORTER_JAEGER_PASSWORD"
)

// CollectorEndpointFromEnv return environment variable value of JAEGER_ENDPOINT
Expand Down Expand Up @@ -70,93 +60,3 @@ func WithDisabledFromEnv() Option {
}
}
}

// ProcessFromEnv parse environment variables into jaeger exporter's Process.
// It will return a nil tag slice if the environment variable JAEGER_TAGS is malformed.
func ProcessFromEnv() Process {
var p Process
if e := os.Getenv(envServiceName); e != "" {
p.ServiceName = e
}
if e := os.Getenv(envTags); e != "" {
tags, err := parseTags(e)
if err != nil {
otel.Handle(err)
} else {
p.Tags = tags
}
}

return p
}

// WithProcessFromEnv uses environment variables and overrides jaeger exporter's Process.
func WithProcessFromEnv() Option {
return func(o *options) {
p := ProcessFromEnv()
if p.ServiceName != "" {
o.Process.ServiceName = p.ServiceName
}
if len(p.Tags) != 0 {
o.Process.Tags = p.Tags
}
}
}

var errTagValueNotFound = errors.New("missing tag value")
var errTagEnvironmentDefaultValueNotFound = errors.New("missing default value for tag environment value")

// parseTags parses the given string into a collection of Tags.
// Spec for this value:
// - comma separated list of key=value
// - value can be specified using the notation ${envVar:defaultValue}, where `envVar`
// is an environment variable and `defaultValue` is the value to use in case the env var is not set
func parseTags(sTags string) ([]attribute.KeyValue, error) {
pairs := strings.Split(sTags, ",")
tags := make([]attribute.KeyValue, len(pairs))
for i, p := range pairs {
field := strings.SplitN(p, "=", 2)
if len(field) != 2 {
return nil, errTagValueNotFound
}
k, v := strings.TrimSpace(field[0]), strings.TrimSpace(field[1])

if strings.HasPrefix(v, "${") && strings.HasSuffix(v, "}") {
ed := strings.SplitN(v[2:len(v)-1], ":", 2)
if len(ed) != 2 {
return nil, errTagEnvironmentDefaultValueNotFound
}
e, d := ed[0], ed[1]
v = os.Getenv(e)
if v == "" && d != "" {
v = d
}
}

tags[i] = parseKeyValue(k, v)
}

return tags, nil
}

func parseKeyValue(k, v string) attribute.KeyValue {
return attribute.KeyValue{
Key: attribute.Key(k),
Value: parseValue(v),
}
}

func parseValue(str string) attribute.Value {
if v, err := strconv.ParseInt(str, 10, 64); err == nil {
return attribute.Int64Value(v)
}
if v, err := strconv.ParseFloat(str, 64); err == nil {
return attribute.Float64Value(v)
}
if v, err := strconv.ParseBool(str); err == nil {
return attribute.BoolValue(v)
}

// Fallback
return attribute.StringValue(str)
}
Loading