Skip to content

Commit

Permalink
Allow service.name otel env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
TimotejKovacka committed Sep 29, 2024
1 parent 1893f39 commit 1b97bf3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/opentelemetry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ func parseJSON(data json.RawMessage) (Config, error) {
func parseEnvs(env map[string]string) (Config, error) {
cfg := Config{}

if serviceName, ok := env["OTEL_SERVICE_NAME"]; ok {
cfg.ServiceName = null.StringFrom(serviceName)
}

err := envconfig.Process("K6_OTEL_", &cfg, func(key string) (string, bool) {
v, ok := env[key]
return v, ok
Expand Down
18 changes: 18 additions & 0 deletions pkg/opentelemetry/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ func TestConfig(t *testing.T) {
},
},

"OTEL environment variables": {
env: map[string]string{
"OTEL_SERVICE_NAME": "otel-service",
},
expectedConfig: Config{
ServiceName: null.StringFrom("otel-service"),
ServiceVersion: null.StringFrom(k6Const.Version),
ExporterType: null.StringFrom(grpcExporterType),
HTTPExporterInsecure: null.NewBool(false, true),
HTTPExporterEndpoint: null.StringFrom("localhost:4318"),
HTTPExporterURLPath: null.StringFrom("/v1/metrics"),
GRPCExporterInsecure: null.NewBool(false, true),
GRPCExporterEndpoint: null.StringFrom("localhost:4317"),
ExportInterval: types.NullDurationFrom(10 * time.Second),
FlushInterval: types.NullDurationFrom(1 * time.Second),
},
},

"JSON complete overwrite": {
jsonRaw: json.RawMessage(
`{` +
Expand Down

0 comments on commit 1b97bf3

Please sign in to comment.