Description
The current implementation uses a hardcoded constant for the APM serviceName:
const serviceName = "package-registry"
This prevents dynamic configuration of the APM service name, which can be useful in:
- multi-instance deployments
- containerized environments
- observability use cases (e.g., grouping services by env or cluster)
- debugging or staging environments where custom service naming is required
Expected behavior
The service name used in APM should:
- Default to
"package-registry" if the environment variable ELASTIC_APM_SERVICE_NAME is not set
- Use the value from
ELASTIC_APM_SERVICE_NAME if present
Proposed implementation
Replace the const with a top-level var initialized with the value of os.Getenv, falling back to the default.
Code snippet:
// Replace this:
const serviceName = "package-registry"
// With this:
var serviceName = getServiceName()
func getServiceName() string {
if name := os.Getenv("ELASTIC_APM_SERVICE_NAME"); name != "" {
return name
}
return "package-registry"
}
This ensures:
- The env variable is only read once
- The same value is consistently used across APM tracer and logger initialization
- Performance and maintainability are preserved
Description
The current implementation uses a hardcoded constant for the APM
serviceName:This prevents dynamic configuration of the APM service name, which can be useful in:
Expected behavior
The service name used in APM should:
"package-registry"if the environment variableELASTIC_APM_SERVICE_NAMEis not setELASTIC_APM_SERVICE_NAMEif presentProposed implementation
Replace the
constwith a top-levelvarinitialized with the value ofos.Getenv, falling back to the default.Code snippet:
This ensures: