diff --git a/pkg/opentelemetry/config.go b/pkg/opentelemetry/config.go index 2833687..562181b 100644 --- a/pkg/opentelemetry/config.go +++ b/pkg/opentelemetry/config.go @@ -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 diff --git a/pkg/opentelemetry/config_test.go b/pkg/opentelemetry/config_test.go index d33968b..de996e6 100644 --- a/pkg/opentelemetry/config_test.go +++ b/pkg/opentelemetry/config_test.go @@ -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( `{` +