Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generated modules that output const &str for tracing compatibility #1334

Merged
merged 5 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions opentelemetry-datadog/src/exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl DatadogPipelineBuilder {
cfg.resource = Cow::Owned(Resource::new(
cfg.resource
.iter()
.filter(|(k, _v)| **k != semcov::resource::SERVICE_NAME)
.filter(|(k, _v)| k.as_str() != semcov::resource::SERVICE_NAME)
.map(|(k, v)| KeyValue::new(k.clone(), v.clone())),
));
cfg
Expand All @@ -226,7 +226,7 @@ impl DatadogPipelineBuilder {
} else {
let service_name = SdkProvidedResourceDetector
.detect(Duration::from_secs(0))
.get(semcov::resource::SERVICE_NAME)
.get(semcov::resource::SERVICE_NAME.into())
.unwrap()
.to_string();
(
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-jaeger/src/exporter/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn build_config_and_process(
let service_name = service_name_opt.unwrap_or_else(|| {
config
.resource
.get(semcov::resource::SERVICE_NAME)
.get(semcov::resource::SERVICE_NAME.into())
.map(|v| v.to_string())
.unwrap_or_else(|| "unknown_service".to_string())
});
Expand All @@ -70,7 +70,7 @@ fn build_config_and_process(
let mut tags = config
.resource
.iter()
.filter(|(key, _)| **key != semcov::resource::SERVICE_NAME)
.filter(|(key, _)| key.as_str() != semcov::resource::SERVICE_NAME)
.map(|(key, value)| KeyValue::new(key.clone(), value.clone()))
.collect::<Vec<KeyValue>>();

Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-otlp/examples/basic-otlp-http/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
"Nice operation!".to_string(),
vec![Key::new("bogons").i64(100)],
);
span.set_attribute(ANOTHER_KEY.string("yes"));
span.set_attribute(KeyValue::new(ANOTHER_KEY, "yes"));

tracer.in_span("Sub operation...", |cx| {
let span = cx.span();
span.set_attribute(LEMONS_KEY.string("five"));
span.set_attribute(KeyValue::new(LEMONS_KEY, "five"));

span.add_event("Sub span event", vec![]);
});
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-otlp/examples/basic-otlp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
"Nice operation!".to_string(),
vec![Key::new("bogons").i64(100)],
);
span.set_attribute(ANOTHER_KEY.string("yes"));
span.set_attribute(KeyValue::new(ANOTHER_KEY, "yes"));

info!(target: "my-target", "hello from {}. My price is {}. I am also inside a Span!", "banana", 2.99);

tracer.in_span("Sub operation...", |cx| {
let span = cx.span();
span.set_attribute(LEMONS_KEY.string("five"));
span.set_attribute(KeyValue::new(LEMONS_KEY, "five"));

span.add_event("Sub span event", vec![]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use opentelemetry::{
global::{shutdown_tracer_provider, tracer},
trace::TraceError,
trace::{TraceContextExt, Tracer},
Key,
Key, KeyValue,
};
use opentelemetry_otlp::WithExportConfig;
use std::{
Expand Down Expand Up @@ -85,11 +85,11 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
"Nice operation!".to_string(),
vec![Key::new("bogons").i64(100)],
);
span.set_attribute(ANOTHER_KEY.string("yes"));
span.set_attribute(KeyValue::new(ANOTHER_KEY, "yes"));

tracer.in_span("Sub operation...", |cx| {
let span = cx.span();
span.set_attribute(LEMONS_KEY.string("five"));
span.set_attribute(KeyValue::new(LEMONS_KEY, "five"));

span.add_event("Sub span event", vec![]);
});
Expand Down
12 changes: 6 additions & 6 deletions opentelemetry-prometheus/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ fn prometheus_exporter_integration() {
.merge(&mut Resource::new(
vec![
// always specify service.name because the default depends on the running OS
SERVICE_NAME.string("prometheus_test"),
KeyValue::new(SERVICE_NAME, "prometheus_test"),
// Overwrite the semconv.TelemetrySDKVersionKey value so we don't need to update every version
TELEMETRY_SDK_VERSION.string("latest"),
KeyValue::new(TELEMETRY_SDK_VERSION, "latest"),
]
.into_iter()
.chain(tc.custom_resource_attrs.into_iter()),
Expand Down Expand Up @@ -390,9 +390,9 @@ fn multiple_scopes() {
)
.merge(&mut Resource::new(vec![
// always specify service.name because the default depends on the running OS
SERVICE_NAME.string("prometheus_test"),
KeyValue::new(SERVICE_NAME, "prometheus_test"),
// Overwrite the semconv.TelemetrySDKVersionKey value so we don't need to update every version
TELEMETRY_SDK_VERSION.string("latest"),
KeyValue::new(TELEMETRY_SDK_VERSION, "latest"),
]));

let provider = MeterProvider::builder()
Expand Down Expand Up @@ -722,9 +722,9 @@ fn duplicate_metrics() {
.merge(&mut Resource::new(
vec![
// always specify service.name because the default depends on the running OS
SERVICE_NAME.string("prometheus_test"),
KeyValue::new(SERVICE_NAME, "prometheus_test"),
// Overwrite the semconv.TelemetrySDKVersionKey value so we don't need to update every version
TELEMETRY_SDK_VERSION.string("latest"),
KeyValue::new(TELEMETRY_SDK_VERSION, "latest"),
]
.into_iter()
.chain(tc.custom_resource_attrs.into_iter()),
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-semantic-conventions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Changed

- Replaced Key constants with &'static str [#1320]
- Bump MSRV to 1.65 [#1318](https://github.com/open-telemetry/opentelemetry-rust/pull/1318)
- Bump MSRV to 1.64 [#1203](https://github.com/open-telemetry/opentelemetry-rust/pull/1203)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,31 @@
//!
//! ## Usage
//!
//! `tracing`:
//!
//! ```
//! use opentelemetry_semantic_conventions as semconv;
//! use tracing::span;
//!
//! let span = span!(
//! LEVEL::INFO,
//! "handle_request",
//! { semconv::resource::SERVICE_NAME = "my-service" },
//! { semconv::resource::SERVICE_NAMESPACE = "my-namespace" }
//! );
//! ```
//!
//! OpenTelemetry SDK:
//!
//! ```
//! use opentelemetry::KeyValue;
//! use opentelemetry_sdk::{trace::{config, TracerProvider}, Resource};
//! use opentelemetry_semantic_conventions as semconv;
//!
//! let _tracer = TracerProvider::builder()
//! .with_config(config().with_resource(Resource::new(vec![
//! semconv::resource::SERVICE_NAME.string("my-service"),
//! semconv::resource::SERVICE_NAMESPACE.string("my-namespace"),
//! KeyValue::new(semconv::resource::SERVICE_NAME, "my-service"),
//! KeyValue::new(semconv::resource::SERVICE_NAMESPACE, "my-namespace"),
//! ])))
//! .build();
//! ```
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,33 @@
//!
//! ## Usage
//!
//! `tracing`:
//!
//! ```
//! use opentelemetry_semantic_conventions as semconv;
//! use tracing::span;
//!
//! let span = span!(
//! LEVEL::INFO,
//! "handle_request",
//! { semconv::trace::NET_PEER_NAME = "example.org" },
//! { semconv::trace::NET_PEER_PORT = 80 }
//! );
//! ```
//!
//! OpenTelemetry SDK:
//!
//! ```
//! use opentelemetry::KeyValue;
//! use opentelemetry::{global, trace::Tracer as _};
//! use opentelemetry_semantic_conventions as semcov;
//! use opentelemetry_semantic_conventions as semconv;
//!
//! let tracer = global::tracer("my-component");
//! let _span = tracer
//! .span_builder("span-name")
//! .with_attributes(vec![
//! semcov::trace::NET_PEER_NAME.string("example.org"),
//! semcov::trace::NET_PEER_PORT.i64(80),
//! KeyValue::new(semconv::trace::NET_PEER_NAME, "example.org"),
//! KeyValue::new(semconv::trace::NET_PEER_PORT, 80i64),
//! ])
//! .start(&tracer);
//! ```
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

{% include 'header_' + conventions + '.rs' %}

use opentelemetry::Key;

{%- for attribute in attributes if attribute.is_local and not attribute.ref %}

/// {% filter escape %}{{attribute.brief | to_doc_brief}}.{% endfilter %}
Expand All @@ -28,5 +26,5 @@ use opentelemetry::Key;
{%- if (attribute.stability | string()) == "StabilityLevel.DEPRECATED" %}
#[deprecated]
{%- endif %}
pub const {{attribute.fqn | to_const_name}}: Key = Key::from_static_str("{{attribute.fqn}}");
pub const {{attribute.fqn | to_const_name}}: &str = "{{attribute.fqn}}";
{%- endfor %}
Loading