Skip to content

Commit

Permalink
Update for tracing instrumentation and error handling (#63)
Browse files Browse the repository at this point in the history
Refactored tracer initialization to use `InstrumentationScope` and updated error handling to match `opentelemetry` version 0.27. Enhanced attribute value handling for unknown values and upgraded dependencies in `Cargo.toml`.

Co-authored-by: Julien Teruel <julien.teruel@worldline.com>
  • Loading branch information
JT117 and Julien Teruel authored Nov 15, 2024
1 parent c481f61 commit 9ee7a0a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ path = "src/lib.rs"

[dependencies]
tracing = "0.1"
opentelemetry = { version = "0.26" }
opentelemetry_sdk = { version = "0.26", features = ["rt-tokio"] }
opentelemetry-semantic-conventions = { version = "0.26" }
opentelemetry = { version = "0.27" }
opentelemetry_sdk = { version = "0.27", features = ["rt-tokio"] }
opentelemetry-semantic-conventions = { version = "0.27" }
gcloud-sdk = { version = "0.25", features = ["google-devtools-cloudtrace-v2"], default-features = false }
rvstruct = "0.3"
rsb_derive = "0.5"
Expand All @@ -40,8 +40,8 @@ tls-webpki-roots = ["gcloud-sdk/tls-webpki-roots"]

[dev-dependencies]
tokio = { version = "1", features = ["full"] }
opentelemetry = { version = "0.26" }
opentelemetry = { version = "0.27" }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter","registry"] }
tracing-opentelemetry = { version = "0.27" }
tracing-opentelemetry = { version = "0.28" }
cargo-husky = { version = "1.5", default-features = false, features = ["run-for-all", "prepush-hook", "run-cargo-fmt"] }
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use gcloud_sdk::error::Error;
use opentelemetry::ExportError;
use opentelemetry::trace::ExportError;
use rsb_derive::*;

pub type BoxedError = Box<dyn std::error::Error + Send + Sync>;
Expand Down
4 changes: 4 additions & 0 deletions src/google_trace_exporter_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ impl GcpCloudTraceExporterClient {
MAX_STR_LEN,
))
}
_ => gcp_attribute_value::Value::StringValue(Self::truncatable_string(
"unknown_value",
MAX_STR_LEN,
)),
}),
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ pub type TraceExportResult<E> = Result<E, crate::errors::GcloudTraceError>;
mod google_trace_exporter_client;
mod span_exporter;

use std::ops::Deref;

use opentelemetry::trace::TracerProvider;
use opentelemetry::InstrumentationScope;
use opentelemetry_sdk::Resource;
pub use span_exporter::GcpCloudTraceExporter;
use std::ops::Deref;

use rsb_derive::*;

Expand Down Expand Up @@ -107,12 +107,13 @@ impl GcpCloudTraceExporterBuilder {
.build()
};

let tracer = provider
.tracer_builder("opentelemetry-gcloud")
let scope = InstrumentationScope::builder("opentelemetry-gcloud")
.with_version(env!("CARGO_PKG_VERSION"))
.with_schema_url("https://opentelemetry.io/schemas/1.23.0")
.build();

let tracer = provider.tracer_with_scope(scope);

let _ = opentelemetry::global::set_tracer_provider(provider);
Ok(tracer)
}
Expand Down

0 comments on commit 9ee7a0a

Please sign in to comment.