Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for otel collector environment variables #3048

Merged

Conversation

jharvey10
Copy link
Contributor

@jharvey10 jharvey10 commented Mar 20, 2025

PR Description

Adds support for converting environment variables in OpenTelemetry Collector config files to equivalent Alloy config syntax.

This is accomplished by:

  • Adding a custom envprovider to override the default config parsing behavior of automatically replacing envvars with avlues
  • Using a regular expression from here to search for environment variable references.
  • Replacing environment variable references with sys.env("NAME_OF_ENV_VAR"), wrapped in a coalese to properly handle default values, if present in the otelcol config.

Which issue(s) this PR fixes

Closes #2947

Notes to the Reviewer

  • Handling the envvars in this way means there's no way to distinguish between an original config of ${FOO} and $${FOO}. The logic will convert both of these to the sys.env format, even though this is not 100% congruent with how OpenTelemetry treats these values.

PR Checklist

  • CHANGELOG.md updated
  • Documentation added
  • Tests updated
  • Config converters updated

@jharvey10 jharvey10 linked an issue Mar 20, 2025 that may be closed by this pull request
@CLAassistant
Copy link

CLAassistant commented Mar 20, 2025

CLA assistant check
All committers have signed the CLA.

@jharvey10 jharvey10 changed the title wip: otel config envvar support feat: add support for otel collector environment variables Mar 21, 2025
Copy link
Contributor

github-actions bot commented Mar 21, 2025

💻 Deploy preview deleted.

@jharvey10 jharvey10 force-pushed the 2947-support-converting-env-variables-from-otel-config-file branch from 20a3f03 to c14c25f Compare March 21, 2025 20:08
@jharvey10 jharvey10 force-pushed the 2947-support-converting-env-variables-from-otel-config-file branch from c14c25f to 58cde49 Compare March 21, 2025 20:09
@jharvey10 jharvey10 marked this pull request as ready for review March 24, 2025 17:53
@jharvey10 jharvey10 requested a review from a team as a code owner March 24, 2025 17:53
@clayton-cornell clayton-cornell added the type/docs Docs Squad label across all Grafana Labs repos label Mar 24, 2025
@clayton-cornell
Copy link
Contributor

Docs are OK.

Copy link
Contributor

@wildum wildum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@jharvey10
Copy link
Contributor Author

@mattdurham @wildum @dehaansa
If this looks good to all of you, would you mind giving me a merge? I would, but I believe I'm still in the probationary period.

@mattdurham mattdurham merged commit 4032dde into main Mar 26, 2025
35 checks passed
@mattdurham mattdurham deleted the 2947-support-converting-env-variables-from-otel-config-file branch March 26, 2025 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/docs Docs Squad label across all Grafana Labs repos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support converting env variables from Otel config file
6 participants