Skip to content

Commit 4fdf560

Browse files
authored
fix(layer)!: use otel semantic conventions for code (#225)
## Motivation The otel semantic conventions specify the names `code.file.path` and `code.line.number` for these attributes. There is no equivalent for module, but I extrapolated from `code.function.name`. https://opentelemetry.io/docs/specs/semconv/code/ ## Solution Rename the current attributes.
1 parent 612b5b2 commit 4fdf560

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Unreleased
22

3+
### Breaking Changes
4+
5+
- The attributes `code.filepath`, `code.lineno`, and `code.namespace` have been renamed to `code.file.path`, and
6+
`code.line.number`, and `code.module.name`, to align with the opentelemetry semantic conventions for code.
7+
38
### Removed
49

510
- Feature `metrics_gauge_unstable` since metrics gauge are stable in upstream now.

src/layer.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,15 +1041,15 @@ where
10411041
let meta = attrs.metadata();
10421042

10431043
if let Some(filename) = meta.file() {
1044-
builder_attrs.push(KeyValue::new("code.filepath", filename));
1044+
builder_attrs.push(KeyValue::new("code.file.path", filename));
10451045
}
10461046

10471047
if let Some(module) = meta.module_path() {
1048-
builder_attrs.push(KeyValue::new("code.namespace", module));
1048+
builder_attrs.push(KeyValue::new("code.module.name", module));
10491049
}
10501050

10511051
if let Some(line) = meta.line() {
1052-
builder_attrs.push(KeyValue::new("code.lineno", line as i64));
1052+
builder_attrs.push(KeyValue::new("code.line.number", line as i64));
10531053
}
10541054
}
10551055

@@ -1283,17 +1283,17 @@ where
12831283
if let Some(file) = file {
12841284
otel_event
12851285
.attributes
1286-
.push(KeyValue::new("code.filepath", file));
1286+
.push(KeyValue::new("code.file.path", file));
12871287
}
12881288
if let Some(module) = module {
12891289
otel_event
12901290
.attributes
1291-
.push(KeyValue::new("code.namespace", module));
1291+
.push(KeyValue::new("code.module.name", module));
12921292
}
12931293
if let Some(line) = meta.line() {
12941294
otel_event
12951295
.attributes
1296-
.push(KeyValue::new("code.lineno", line as i64));
1296+
.push(KeyValue::new("code.line.number", line as i64));
12971297
}
12981298
}
12991299

@@ -1833,9 +1833,9 @@ mod tests {
18331833

18341834
let attributes = tracer.attributes();
18351835

1836-
assert!(attributes.contains_key("code.filepath"));
1837-
assert!(attributes.contains_key("code.namespace"));
1838-
assert!(attributes.contains_key("code.lineno"));
1836+
assert!(attributes.contains_key("code.file.path"));
1837+
assert!(attributes.contains_key("code.module.name"));
1838+
assert!(attributes.contains_key("code.line.number"));
18391839
}
18401840

18411841
#[test]
@@ -1863,9 +1863,9 @@ mod tests {
18631863

18641864
let attributes = tracer.attributes();
18651865

1866-
assert!(!attributes.contains_key("code.filepath"));
1867-
assert!(!attributes.contains_key("code.namespace"));
1868-
assert!(!attributes.contains_key("code.lineno"));
1866+
assert!(!attributes.contains_key("code.file.path"));
1867+
assert!(!attributes.contains_key("code.module.name"));
1868+
assert!(!attributes.contains_key("code.line.number"));
18691869
}
18701870

18711871
#[test]

0 commit comments

Comments
 (0)