Skip to content

[ER] Make serviceName configurable via ELASTIC_APM_SERVICE_NAME environment variable #1436

Description

@fred-maussion

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions