Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions data_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,25 @@ var suites = []FixtureSuite{
Spans: 1,
},
},
// OTEL_SERVICE_NAME
{
Name: "otel-cli span with envvar service name (recording)",
Config: FixtureConfig{
CliArgs: []string{"span"},
Env: map[string]string{
"OTEL_EXPORTER_OTLP_ENDPOINT": "{{endpoint}}",
"OTEL_SERVICE_NAME": "test-service-123abc",
},
TestTimeoutMs: 1000,
},
Expect: Results{
Config: otelcli.DefaultConfig(),
SpanData: map[string]string{
"service_attributes": "service.name=test-service-123abc",
},
Spans: 1,
},
},
},
// otel-cli span --print-tp actually prints
{
Expand Down
5 changes: 4 additions & 1 deletion otelcli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type Config struct {
Blocking bool `json:"otlp_blocking" env:"OTEL_EXPORTER_OTLP_BLOCKING"`
NoTlsVerify bool `json:"no_tls_verify" env:"OTEL_CLI_NO_TLS_VERIFY"`

ServiceName string `json:"service_name" env:"OTEL_CLI_SERVICE_NAME"`
ServiceName string `json:"service_name" env:"OTEL_CLI_SERVICE_NAME,OTEL_SERVICE_NAME"`
SpanName string `json:"span_name" env:"OTEL_CLI_SPAN_NAME"`
Kind string `json:"span_kind" env:"OTEL_CLI_TRACE_KIND"`
Attributes map[string]string `json:"span_attributes" env:"OTEL_CLI_ATTRIBUTES"`
Expand Down Expand Up @@ -124,6 +124,9 @@ func (c *Config) LoadEnv(getenv func(string) string) error {
for i := 0; i < structType.NumField(); i++ {
field := structType.Field(i)
envVars := field.Tag.Get("env")
if envVars == "" {
continue
}
// a field can have multiple comma-delimiated env vars to look in
for _, envVar := range strings.Split(envVars, ",") {
// call the provided func(string)string provided to get the
Expand Down