Skip to content

WIP - feat(o11y): use local crate name as tracing target#5197

Draft
haphungw wants to merge 1 commit intogoogleapis:mainfrom
haphungw:wip-client-logging-macro
Draft

WIP - feat(o11y): use local crate name as tracing target#5197
haphungw wants to merge 1 commit intogoogleapis:mainfrom
haphungw:wip-client-logging-macro

Conversation

@haphungw
Copy link
Copy Markdown
Contributor

Refactor the WithClientLogging component to dynamically assign the tracing::event! target field to the name of the crate emitting the log (e.g., google-cloud-storage).

To implement log separation per-client, we converted WithClientLogging from a generic struct wrapping a Future into a #[macro_export]. When client_request_signals! holds a pending HTTP future inside a generated client crate, it expands the new macro locally. env!("CARGO_PKG_NAME") locks onto that caller crate's name, injecting it into the tracing target literal at compile time.

Fixes #5150

Comment on lines +42 to +48
let inner_future = $inner;
async move {
let output = inner_future.await;
if let Some(snapshot) =
$crate::observability::RequestRecorder::current().map(|r| r.client_snapshot())
{
if let Err(error) = &output {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider:

Suggested change
let inner_future = $inner;
async move {
let output = inner_future.await;
if let Some(snapshot) =
$crate::observability::RequestRecorder::current().map(|r| r.client_snapshot())
{
if let Err(error) = &output {
async move {
$inner.await.inspect_err(|error| {
let Some(snapshot) =
$crate::observability::RequestRecorder::current().map(|r| r.client_snapshot()) else { return; }
... ...
::tracing::event!(
name: "experimental.client.request.error",
target: env!("CARGO_PKG_NAME"),
::tracing::Level::WARN,
// Use literals because we don't want to re-export the constants.
"rpc.system.name" = snapshot.rpc_system(),
... ... ...
);
})
}

@googleapis googleapis deleted a comment from google-cla bot Mar 30, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.01%. Comparing base (2cc182b) to head (39e0363).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5197   +/-   ##
=======================================
  Coverage   98.01%   98.01%           
=======================================
  Files         214      214           
  Lines       44110    44110           
=======================================
  Hits        43236    43236           
  Misses        874      874           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Use client_artifact for the logging target

2 participants