Skip to content

L125: Python Abseil Logging Support#505

Merged
sergiitk merged 13 commits intogrpc:masterfrom
sreenithi:absl_log_init_proposal
Jan 13, 2026
Merged

L125: Python Abseil Logging Support#505
sergiitk merged 13 commits intogrpc:masterfrom
sreenithi:absl_log_init_proposal

Conversation

@sreenithi
Copy link
Contributor

@sreenithi sreenithi commented Jul 4, 2025

Proposes changes to Abseil logging initialization in gRPC Python to resolve the issue the absl warning All log messages before absl::InitializeLog() is called are written to STDERR.

Related:

@sreenithi sreenithi self-assigned this Jul 4, 2025
Co-authored-by: Ashesh Vidyut <134911583+asheshvidyut@users.noreply.github.com>
Copy link
Member

@sergiitk sergiitk left a comment

Choose a reason for hiding this comment

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

As discussed IRL.

Copy link
Member

@sergiitk sergiitk left a comment

Choose a reason for hiding this comment

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

LGTM, but let's ask Mark to give this a look once the remaining feedback is addressed.

Comment on lines +33 to +35
> Note that if abseil fixes https://github.com/abseil/abseil-cpp/issues/1656,
> gRPC Core itself will be able to invoke absl::InitializeLog(), but until then
> this is a workaround.
Copy link
Member

Choose a reason for hiding this comment

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

Looking at the ticket - I don't think its point is to allow to "Core itself" .. "to invoke absl::InitializeLog()", but to "Make absl::InitializeLog safe to be called multiple times", making the call a no-op if already been called. We'll still have to call it from Cython.

I think we should remove this block.

Copy link
Member

Choose a reason for hiding this comment

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

Discussed IRL, to be rephrased to make it clear the call may be moved to gRPC Core depending on how abseil/abseil-cpp#1656 is resoved.

[L117][L117].

After this change, gRPC python users started seeing the warning log -
`WARNING: All log messages before absl::InitializeLog() is called are written to STDERR`.
Copy link
Member

Choose a reason for hiding this comment

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

How do we reproduce this? I was only able to get it printed with export GRPC_VERBOSITY=INFO (which also prints out Log level INFO is not suitable for production. Prefer WARNING or ERROR. However if you see this message in a debug environment or test environment it is safe to ignore this message., or with export GRPC_TRACE=connectivity_state (or any other module).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was able to reproduce by setting GRPC_VERBOSITY=debug

_initialize()
```

### Behaviour with multiple imports of gRPC
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
### Behaviour with multiple imports of gRPC
### Behavior with multiple imports of gRPC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is yet another Americal vs British English differences I suppose. I was using the British English spelling, however changed as suggested now :)

@sreenithi
Copy link
Contributor Author

sreenithi commented Nov 21, 2025

LGTM, but let's ask Mark to give this a look once the remaining feedback is addressed.

addressed the feedback. @markdroth PTAL and let us know your comments too before we open for public review.

@sreenithi sreenithi requested a review from markdroth November 24, 2025 06:34
@sergiitk sergiitk merged commit 6a56c3c into grpc:master Jan 13, 2026
1 check passed
copybara-service bot pushed a commit to grpc/grpc that referenced this pull request Jan 20, 2026
After Core recently changed its logging system to use absl logging, gRPC python users started seeing the warning log
`WARNING: All log messages before absl::InitializeLog() is called are written to STDERR.`

This issue especially affects users who are indirect users of the gRPC Python  library too, such as Gemini API users.

`absl::InitializeLog()` is a C++ library that cannot directly be called in the Python layer. It is hence added in the Cython layer at the time of initializing.
The Python layer so far did not have a dependency on the absl library, hence this PR also adds an external dependency on `absl/log:initialize`

Design gRFC for this: grpc/proposal#505

----
DO NOT SUBMIT. This PR is for testing purposes only. [cl/858528872](http://cl/858528872) [cl/858287174](http://cl/858287174)

PiperOrigin-RevId: 858528872
copybara-service bot pushed a commit to grpc/grpc that referenced this pull request Jan 20, 2026
After Core recently changed its logging system to use absl logging, gRPC python users started seeing the warning log
`WARNING: All log messages before absl::InitializeLog() is called are written to STDERR.`

This issue especially affects users who are indirect users of the gRPC Python  library too, such as Gemini API users.

`absl::InitializeLog()` is a C++ library that cannot directly be called in the Python layer. It is hence added in the Cython layer at the time of initializing.
The Python layer so far did not have a dependency on the absl library, hence this PR also adds an external dependency on `absl/log:initialize`

Design gRFC for this: grpc/proposal#505

----
DO NOT SUBMIT. This PR is for testing purposes only. [cl/858528872](http://cl/858528872) [cl/858287174](http://cl/858287174)

PiperOrigin-RevId: 858528872
copybara-service bot pushed a commit to grpc/grpc that referenced this pull request Jan 20, 2026
After Core recently changed its logging system to use absl logging, gRPC python users started seeing the warning log
`WARNING: All log messages before absl::InitializeLog() is called are written to STDERR.`

This issue especially affects users who are indirect users of the gRPC Python  library too, such as Gemini API users.

`absl::InitializeLog()` is a C++ library that cannot directly be called in the Python layer. It is hence added in the Cython layer at the time of initializing.
The Python layer so far did not have a dependency on the absl library, hence this PR also adds an external dependency on `absl/log:initialize`

Design gRFC for this: grpc/proposal#505

----
DO NOT SUBMIT. This PR is for testing purposes only. [cl/858528872](http://cl/858528872) [cl/858287174](http://cl/858287174)

PiperOrigin-RevId: 858528872
ctiller pushed a commit to grpc/grpc that referenced this pull request Feb 4, 2026
Fixes #38703

After Core recently changed its logging system to use absl logging, gRPC python users started seeing the warning log
`WARNING: All log messages before absl::InitializeLog() is called are written to STDERR.`

This issue especially affects users who are indirect users of the gRPC Python  library too, such as Gemini API users.

`absl::InitializeLog()` is a C++ library that cannot directly be called in the Python layer. It is hence added in the Cython layer at the time of initializing.
The Python layer so far did not have a dependency on the absl library, hence this PR also adds an external dependency on `absl/log:initialize`

Design gRFC for this: grpc/proposal#505

Closes #39779

COPYBARA_INTEGRATE_REVIEW=#39779 from sreenithi:absl_init_log_python d53d529
PiperOrigin-RevId: 865415667
copybara-service bot pushed a commit to grpc/grpc that referenced this pull request Feb 13, 2026
Fixes #38703

After Core recently changed its logging system to use absl logging, gRPC python users started seeing the warning log
`WARNING: All log messages before absl::InitializeLog() is called are written to STDERR.`

This issue especially affects users who are indirect users of the gRPC Python  library too, such as Gemini API users.

`absl::InitializeLog()` is a C++ library that cannot directly be called in the Python layer. It is hence added in the Cython layer at the time of initializing.
The Python layer so far did not have a dependency on the absl library, hence this PR also adds an external dependency on `absl/log:initialize`

Design gRFC for this: grpc/proposal#505

Closes #39779

COPYBARA_INTEGRATE_REVIEW=#39779 from sreenithi:absl_init_log_python 59eb1e5
PiperOrigin-RevId: 869586957
sreenithi added a commit to sreenithi/grpc that referenced this pull request Feb 16, 2026
Fixes grpc#38703

After Core recently changed its logging system to use absl logging, gRPC python users started seeing the warning log
`WARNING: All log messages before absl::InitializeLog() is called are written to STDERR.`

This issue especially affects users who are indirect users of the gRPC Python  library too, such as Gemini API users.

`absl::InitializeLog()` is a C++ library that cannot directly be called in the Python layer. It is hence added in the Cython layer at the time of initializing.
The Python layer so far did not have a dependency on the absl library, hence this PR also adds an external dependency on `absl/log:initialize`

Design gRFC for this: grpc/proposal#505

Closes grpc#39779

COPYBARA_INTEGRATE_REVIEW=grpc#39779 from sreenithi:absl_init_log_python 59eb1e5
PiperOrigin-RevId: 869586957
sergiitk pushed a commit to grpc/grpc that referenced this pull request Feb 17, 2026
Backport of #39779 to v1.78.x.
---
Fixes #38703 

After Core recently changed its logging system to use absl logging, gRPC
python users started seeing the warning log
`WARNING: All log messages before absl::InitializeLog() is called are
written to STDERR.`

This issue especially affects users who are indirect users of the gRPC
Python library too, such as Gemini API users.

`absl::InitializeLog()` is a C++ library that cannot directly be called
in the Python layer. It is hence added in the Cython layer at the time
of initializing.
The Python layer so far did not have a dependency on the absl library,
hence this PR also adds an external dependency on `absl/log:initialize`

Design gRFC for this: grpc/proposal#505

However, abseil-cpp currently [doesn't allow `absl::InitializeLog()` to
be called more than
once](abseil/abseil-cpp#1656), and will result
in an error like:
```
[globals.cc : 104] RAW: absl::log_internal::SetTimeZone() has already been called
```
The changes in this PR may hence cause problems to a small percentage of
users with a custom build that's linking directly against gRPC Cython
code, and then call absl::InitializeLog() (directly or transitively).

To solve this problem, this PR also introduces a new environment
variable `GRPC_PYTHON_DISABLE_ABSL_INIT_LOG` that will allow users to
opt-out of this automatic abseil log initialization when set.
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.

4 participants