Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion guide/samples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ google-cloud-wkt.workspace = true
storage-samples.workspace = true
serde_json.workspace = true
tokio = { workspace = true, features = ["full", "macros"] }
tracing-subscriber = { workspace = true, default-features = true }
tracing-subscriber = { workspace = true, features = ["json"] }
opentelemetry = { workspace = true }
opentelemetry-otlp = { workspace = true, features = ["grpc-tonic", "trace"] }
opentelemetry_sdk = { workspace = true, features = ["rt-tokio"] }
tracing-opentelemetry = { workspace = true }
tracing = { workspace = true }
# Formatting trick: this comment preserves formatting in the preceding block.
google-cloud-compute-v1 = { workspace = true, default-features = false, features = [
"default-rustls-provider",
Expand Down
1 change: 1 addition & 0 deletions guide/samples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod error_handling;
pub mod examine_error_details;
pub mod gemini;
pub mod logging;
pub mod observability;
pub mod pagination;
pub mod retry_policies;
pub mod update_resource;
37 changes: 37 additions & 0 deletions guide/samples/src/observability/logging.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// [START rust_observability_logging] ANCHOR: rust_observability_logging
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't have plans to use these in the mdBook, right? We can skip the ANCHOR: and ANCHOR_END if that is the case.

use google_cloud_secretmanager_v1::client::SecretManagerService;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

pub async fn sample() -> anyhow::Result<()> {
// Output `WARN` logs for failed logical client requests, and `DEBUG` logs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe:

Suggested change
// Output `WARN` logs for failed logical client requests, and `DEBUG` logs
// Enable all `WARN` logs, including those failed logical client requests in all client libraries.
// In addition, enable `DEBUG` logs for `google_cloud_secretmanager_v1`, which include
// errors in low-level RPC attempts.

I am not sure if a casual reader of this would understand what "logical client request" means. The surrounding text may need to clarify this.

// for failed low-level RPC attempts from the client library crate.
let filter = tracing_subscriber::EnvFilter::new("warn,google_cloud_secretmanager=debug");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The crate name (and target) is google_cloud_secretmanager**_v1**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since targets are still hardcoded to experimental. (#5150), should we use the working filter in this sample now, or wait until the issue is resolved?


tracing_subscriber::registry()
.with(filter)
.with(tracing_subscriber::fmt::layer().json())
.init();

let _client = SecretManagerService::builder()
.with_tracing()
.build()
.await?;

Ok(())
}
// [END rust_observability_logging] ANCHOR_END: rust_observability_logging
16 changes: 16 additions & 0 deletions guide/samples/src/observability/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod logging;
pub mod tracing;
44 changes: 44 additions & 0 deletions guide/samples/src/observability/tracing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// [START rust_observability_tracing] ANCHOR: rust_observability_tracing
use google_cloud_secretmanager_v1::client::SecretManagerService;
use tracing_subscriber::Registry;
use tracing_subscriber::layer::SubscriberExt;

pub async fn sample() -> anyhow::Result<()> {
use opentelemetry::trace::TracerProvider as _;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: group with the other use declarations.

let exporter = opentelemetry_otlp::SpanExporter::builder()
.with_tonic()
.build()?;
let provider = opentelemetry_sdk::trace::SdkTracerProvider::builder()
.with_batch_exporter(exporter)
.build();
let tracer = provider.tracer("example");

// Create a tracing layer that sends data to an OpenTelemetry Collector running on localhost.
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);

// Register the subscriber globally
let subscriber = Registry::default().with(telemetry);
tracing::subscriber::set_global_default(subscriber)?;

let _client = SecretManagerService::builder()
.with_tracing()
.build()
.await?;

Ok(())
}
// [END rust_observability_tracing] ANCHOR_END: rust_observability_tracing
Loading