Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.
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
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