{"record":{"id":"177a9a05a007dd3f","repo":"grafana/k6","slug":"providing-service-name-is-required","errorCode":null,"errorMessage":"providing service name is required","messagePattern":"providing service name is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/output/opentelemetry/config.go","lineNumber":210,"sourceCode":"\tif v.Headers.Valid {\n\t\tcfg.Headers = v.Headers\n\t}\n\n\tif v.HTTPUsername.Valid {\n\t\tcfg.HTTPUsername = v.HTTPUsername\n\t}\n\n\tif v.HTTPPassword.Valid {\n\t\tcfg.HTTPPassword = v.HTTPPassword\n\t}\n\n\treturn cfg\n}\n\n// Validate validates the config\nfunc (cfg Config) Validate() error {\n\tif cfg.ServiceName.String == \"\" {\n\t\treturn errors.New(\"providing service name is required\")\n\t}\n\t// TODO: it's not actually required, but we should probably have a default\n\t// check if it works without it\n\tif cfg.ServiceVersion.String == \"\" {\n\t\treturn errors.New(\"providing service version is required\")\n\t}\n\tif err := cfg.validateExporterProtocol(); err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}\n\nfunc (cfg Config) validateExporterProtocol() error {\n\tif cfg.ExporterProtocol.String != \"\" {\n\t\tif cfg.ExporterProtocol.String != grpcExporterProtocol && cfg.ExporterProtocol.String != httpExporterProtocol {\n\t\t\treturn fmt.Errorf(\n\t\t\t\t\"unsupported exporter protocol %q, only %q and %q are supported\",\n\t\t\t\tcfg.ExporterProtocol.String,","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/output/opentelemetry/config.go#L192-L228","documentation":"Thrown by Config.Validate() for the OpenTelemetry output when the resolved service name is empty. OTLP metric exporters require a service.name resource attribute, so k6 refuses to start the experimental-opentelemetry output (-o experimental-opentelemetry) without one.","triggerScenarios":"Running with -o experimental-opentelemetry while neither K6_OTEL_SERVICE_NAME nor a serviceName in the output JSON config is set; setting K6_OTEL_SERVICE_NAME=\"\" (empty string) or a whitespace-only value; CI templates that export the variable conditionally and leave it blank.","commonSituations":"First-time OTel setup where the user wires only the exporter endpoint and forgets resource attributes; environments where the service name env var failed to expand (K6_OTEL_SERVICE_NAME= in a .env file); shared scripts reused across teams with different naming.","solutions":["Set K6_OTEL_SERVICE_NAME to a meaningful value, e.g. K6_OTEL_SERVICE_NAME=my-service-loadtest","Or pass it in the output argument JSON: -o experimental-opentelemetry=\"serviceName=my-service\"","Audit .env/CI variable expansion to ensure the value is non-empty at runtime"],"exampleFix":"# before\nk6 run -o experimental-opentelemetry=grpc=http://localhost:4317 script.js\n# -> providing service name is required\n\n# after\nK6_OTEL_SERVICE_NAME=my-service k6 run -o experimental-opentelemetry=grpc=http://localhost:4317 script.js","handlingStrategy":"validation","validationCode":": \"${K6_OTEL_SERVICE_NAME:?K6_OTEL_SERVICE_NAME must be set for the opentelemetry output}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create a wrapper script that hard-requires the service name before invoking k6 with -o experimental-opentelemetry","Keep OTel settings in one sourced env file so name/version/endpoint are always set together","Derive service name from CI_JOB_NAME or repo name automatically"],"tags":["k6","opentelemetry","otlp","config","service-name"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}