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

refactor: reduce and simplify usage of getEnv() #4799

Merged
merged 4 commits into from
Jun 25, 2024

Conversation

danstarns
Copy link
Contributor

@danstarns danstarns commented Jun 15, 2024

In most of the exporters, there is a function getEnv() that is called an unnecessary amount of times inside nested ternary operators.

It looks as getEnv() calls parseEnvironment() that happens to iterate over a large static object parsing its values and performing other assertions.

See extract from source:

  getDefaultUrl(config: OTLPExporterNodeConfigBase): string {
    return typeof config.url === 'string'
      ? config.url
      : getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
      ? appendRootPathToUrlIfNeeded(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT)
      : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
      ? appendResourcePathToUrl(
          getEnv().OTEL_EXPORTER_OTLP_ENDPOINT,
          DEFAULT_COLLECTOR_RESOURCE_PATH
        )
      : DEFAULT_COLLECTOR_URL;
  }

This PR reduces the total invocations of getEnv along the exporters in the hope of easing performance and readability.

@danstarns danstarns requested a review from a team as a code owner June 15, 2024 21:17
Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Thanks. This is more readable now 👍

FYI performance-wise this would not change a lot since all the changed functions are not called on a hot path (only once on start-up).

@pichlermarc
Copy link
Member

Please also add a changelog entry to the unrelased section, subsection enhancement in CHANGELOG.md and experimental/CHANGELOG.md then we can merge this. 🙂

@danstarns
Copy link
Contributor Author

Please also add a changelog entry to the unrelased section, subsection enhancement in CHANGELOG.md and experimental/CHANGELOG.md then we can merge this. 🙂

Updated @pichlermarc 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants