Skip to content

Commit

Permalink
equinix-labs#11 support OTEL_SERVICE_NAME per spec (equinix-labs#158)
Browse files Browse the repository at this point in the history
Solves a request in equinix-labs#11.

* add failing test for OTEL_SERVICE_NAME

* add OTEL_SERVICE_NAME

Also shortcut config items that don't have envvars.
  • Loading branch information
tobert authored Feb 16, 2023
1 parent 3cb4c14 commit 52f1143
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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

0 comments on commit 52f1143

Please sign in to comment.