Skip to content

Commit f7cc03e

Browse files
refactor: Rename span event methods to simplify API and remove example
1 parent 0e07327 commit f7cc03e

File tree

5 files changed

+18
-93
lines changed

5 files changed

+18
-93
lines changed

CHANGELOG.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
### Added
44

5-
- Add `OpenTelemetrySpanExt::add_otel_span_event` function to allow adding OpenTelemetry
6-
events directly to a `tracing::Span`, enabling the use of dynamic attribute keys.
7-
- Add `OpenTelemetrySpanExt::add_otel_span_event_with_timestamp` function, similar to
8-
`add_otel_span_event`, but allowing a specific `SystemTime` to be provided for the event.
9-
- Add `examples/opentelemetry-span-event.rs` demonstrating the usage of the new span event methods.
5+
- Add `OpenTelemetrySpanExt::add_event` and `OpenTelemetrySpanExt::add_event_with_timestamp`
6+
functions to allow adding OpenTelemetry events directly to a `tracing::Span`, enabling the use of dynamic attribute keys
7+
and custom event timestamps.
108

119
# 0.30.0 (March 23, 2025)
1210

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The crate provides the following types:
4545
injected and extracted from a `tracing` [span]. It also provides methods
4646
to directly set span attributes (`set_attribute`), span status (`set_status`),
4747
and add OpenTelemetry events with dynamic attributes using the current time
48-
(`add_otel_span_event`) or a specific timestamp (`add_otel_span_event_with_timestamp`).
48+
(`add_event`) or a specific timestamp (`add_event_with_timestamp`).
4949

5050
[`OpenTelemetryLayer`]: https://docs.rs/tracing-opentelemetry/latest/tracing_opentelemetry/struct.OpenTelemetryLayer.html
5151
[`OpenTelemetrySpanExt`]: https://docs.rs/tracing-opentelemetry/latest/tracing_opentelemetry/trait.OpenTelemetrySpanExt.html

examples/opentelemetry-span-event.rs

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/span_ext.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,18 @@ pub trait OpenTelemetrySpanExt {
177177
/// ];
178178
///
179179
/// // Add event using the extension method
180-
/// app_root.add_otel_span_event("job_started".to_string(), dynamic_attrs);
180+
/// app_root.add_event("job_started".to_string(), dynamic_attrs);
181181
///
182182
/// // ... perform work ...
183183
///
184-
/// app_root.add_otel_span_event("job_completed", vec![KeyValue::new("status", "success")]);
184+
/// app_root.add_event("job_completed", vec![KeyValue::new("status", "success")]);
185185
/// ```
186-
fn add_otel_span_event<T>(&self, name: T, attributes: Vec<KeyValue>)
186+
fn add_event<T>(&self, name: T, attributes: Vec<KeyValue>)
187187
where
188188
T: Into<Cow<'static, str>>;
189189

190190
/// Adds an OpenTelemetry event with a specific timestamp directly to this span.
191-
/// Similar to `add_otel_span_event`, but allows overriding the event timestamp.
191+
/// Similar to `add_event`, but allows overriding the event timestamp.
192192
///
193193
/// # Examples
194194
///
@@ -205,9 +205,9 @@ pub trait OpenTelemetrySpanExt {
205205
/// let event_attrs = vec![KeyValue::new("record_id", "rec-456")];
206206
/// let event_name: Cow<'static, str> = "event_from_past".into();
207207
///
208-
/// app_root.add_otel_span_event_with_timestamp(event_name, event_time, event_attrs);
208+
/// app_root.add_event_with_timestamp(event_name, event_time, event_attrs);
209209
/// ```
210-
fn add_otel_span_event_with_timestamp<T>(
210+
fn add_event_with_timestamp<T>(
211211
&self,
212212
name: T,
213213
timestamp: SystemTime,
@@ -307,19 +307,15 @@ impl OpenTelemetrySpanExt for tracing::Span {
307307
});
308308
}
309309

310-
fn add_otel_span_event<T>(&self, name: T, attributes: Vec<KeyValue>)
310+
fn add_event<T>(&self, name: T, attributes: Vec<KeyValue>)
311311
where
312312
T: Into<Cow<'static, str>>,
313313
{
314-
self.add_otel_span_event_with_timestamp(name, time::now(), attributes);
314+
self.add_event_with_timestamp(name, time::now(), attributes);
315315
}
316316

317-
fn add_otel_span_event_with_timestamp<T>(
318-
&self,
319-
name: T,
320-
timestamp: SystemTime,
321-
attributes: Vec<KeyValue>,
322-
) where
317+
fn add_event_with_timestamp<T>(&self, name: T, timestamp: SystemTime, attributes: Vec<KeyValue>)
318+
where
323319
T: Into<Cow<'static, str>>,
324320
{
325321
self.with_subscriber(move |(id, subscriber)| {

tests/span_ext.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn set_status_helper(status: Status) -> SpanData {
7373
}
7474

7575
#[test]
76-
fn test_add_otel_span_event() {
76+
fn test_add_event() {
7777
let (_tracer, provider, exporter, subscriber) = test_tracer();
7878

7979
let event_name = "my_event";
@@ -87,7 +87,7 @@ fn test_add_otel_span_event() {
8787
let _enter = root.enter(); // Enter span to make it current for the event addition
8888

8989
// Add the event using the new extension method
90-
root.add_otel_span_event(event_name, event_attrs.clone());
90+
root.add_event(event_name, event_attrs.clone());
9191
});
9292

9393
drop(provider); // flush all spans
@@ -111,7 +111,7 @@ fn test_add_otel_span_event() {
111111
}
112112

113113
#[test]
114-
fn test_add_otel_span_event_with_timestamp() {
114+
fn test_add_event_with_timestamp() {
115115
use std::time::{Duration, SystemTime};
116116

117117
let (_tracer, provider, exporter, subscriber) = test_tracer();
@@ -126,11 +126,7 @@ fn test_add_otel_span_event_with_timestamp() {
126126
let _enter = root.enter();
127127

128128
// Add the event using the new extension method with the specific timestamp
129-
root.add_otel_span_event_with_timestamp(
130-
event_name,
131-
specific_timestamp,
132-
event_attrs.clone(),
133-
);
129+
root.add_event_with_timestamp(event_name, specific_timestamp, event_attrs.clone());
134130
});
135131

136132
drop(provider); // flush all spans

0 commit comments

Comments
 (0)