Skip to content

Add credentials environment variables to let ChannelCredentials and Session be injected#4689

Merged
aabmass merged 40 commits intoopen-telemetry:mainfrom
DylanRussell:add_cred_envvar
Sep 9, 2025
Merged

Add credentials environment variables to let ChannelCredentials and Session be injected#4689
aabmass merged 40 commits intoopen-telemetry:mainfrom
DylanRussell:add_cred_envvar

Conversation

@DylanRussell
Copy link
Copy Markdown
Contributor

Description

Add environment variables to allow ChannelCredentials and Session to be injected into OTLP exporters for auto instrumentation. See #4459 for more details..

Fixes # 4459

Type of change

Please delete options that are not relevant.

  • [x ] New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Unit tests

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • [x ] No.

Checklist:

  • [ x] Followed the style guidelines of this project
  • Changelogs have been updated
  • [ x] Unit tests have been added
  • Documentation has been updated
@DylanRussell DylanRussell requested a review from a team as a code owner July 17, 2025 20:55
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py Outdated
Comment thread CHANGELOG.md Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py Outdated
@xrmx xrmx moved this to Ready for review in Python PR digest Aug 18, 2025
@DylanRussell
Copy link
Copy Markdown
Contributor Author

DylanRussell commented Aug 25, 2025

I'm realizing there's 3 ways to do this in the exporters:

  1. Have HTTP AND GRPC specific env vars for metrics/logs/traces.
  2. Just one set of env vars for metrics/logs/traces that encompasses HTTP / GRPC, and we pass "HTTP" or "GRPC" to the entry point as an argument...
  3. Just one set of env vars, and the entry point provider has 2 entry points (one for HTTP one for GRPC), and the user must set the right entry point name in the env var depending on if they want HTTP or GRPC..

I'm going forward with #2 since that's simplest for both the user and the entry point provider. So the function signature that gets associated w/ the entry point should look like:

def credential_provider(otlp_exporter_type: Literal["HTTP", "GRPC"]) -> Union[requests.Session, grpc.ChannelCredentials]
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py Outdated
Comment thread tox.ini
Comment thread dev-requirements.txt
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py Outdated
Copy link
Copy Markdown
Contributor

@xrmx xrmx left a comment

Choose a reason for hiding this comment

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

Confused by the tox.ini changes but lgtm

@DylanRussell
Copy link
Copy Markdown
Contributor Author

Yeah I'm having issues w/ pytest in the venv created by tox..

It is supposedly installed by the test, but I get the following error Exception running subprocess [Errno 2] No such file or directory: 'pytest'

If I then run uv pip install pytest I then get failed with pytest is not allowed, use allowlist_externals to allow it.. If I then add pytest to allowlist_externals I can run the test..

@aabmass
Copy link
Copy Markdown
Member

aabmass commented Sep 9, 2025

Does it pass CI on Github if you just revert those files back to main?

@DylanRussell
Copy link
Copy Markdown
Contributor Author

yeah it works. reverted the change

@aabmass aabmass merged commit d6c0441 into open-telemetry:main Sep 9, 2025
468 of 469 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for review to Done in Python PR digest Sep 9, 2025
JWinermaSplunk pushed a commit to JWinermaSplunk/opentelemetry-python that referenced this pull request Feb 17, 2026
… `Session` be injected (open-telemetry#4689)

* Initial Commit

* Fix broken tests

* Start writing test

* Fix tests

* Add changelog

* Improne and fix _init_exporter func

* Fix desc

* Run precommit and update variable

* Update changelog

* Fix_type

* Commit changes

* Add test

* fix envvar and typecheck

* Precommit and constraints

* Move change to exporter

* Move common code to util.

* Fix lint err and print statment

* Update opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py

Co-authored-by: Aaron Abbott <aaronabbott@google.com>

* Respond to comments

* Ruff

* Document  the entry points better

* Going with factory function approach w/ 2 entry points

* Add tests.. Fix tox.ini ?

* Add http/grpc env var variants

* Respond to comments

* Rename python env var with _

* Precommit

* Commit changes

* add new line

* Fix docs error..

* get rid of envvar in docstring

* Revert tox.ini changes

* Revert tox

---------

Co-authored-by: Aaron Abbott <aaronabbott@google.com>
JWinermaSplunk pushed a commit to JWinermaSplunk/opentelemetry-python that referenced this pull request Feb 17, 2026
… `Session` be injected (open-telemetry#4689)

* Initial Commit

* Fix broken tests

* Start writing test

* Fix tests

* Add changelog

* Improne and fix _init_exporter func

* Fix desc

* Run precommit and update variable

* Update changelog

* Fix_type

* Commit changes

* Add test

* fix envvar and typecheck

* Precommit and constraints

* Move change to exporter

* Move common code to util.

* Fix lint err and print statment

* Update opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py

Co-authored-by: Aaron Abbott <aaronabbott@google.com>

* Respond to comments

* Ruff

* Document  the entry points better

* Going with factory function approach w/ 2 entry points

* Add tests.. Fix tox.ini ?

* Add http/grpc env var variants

* Respond to comments

* Rename python env var with _

* Precommit

* Commit changes

* add new line

* Fix docs error..

* get rid of envvar in docstring

* Revert tox.ini changes

* Revert tox

---------

Co-authored-by: Aaron Abbott <aaronabbott@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

7 participants