Skip to content

Commit cd54f70

Browse files
alocayDaleSeo
authored andcommitted
feat: adding ability to omit attributes for traces and metrics (#358)
* feat: adding ability to omit attributes for traces and metrics * chore: adding changeset * chore: updating changeset text * chore: removing unused file * chore: renaming exporter file * chore: renaming module * re-running checks * chore: auto-gen the as_str function using enums instead of constants * chore: updating changeset entry and fixing fields in instruemnt attribute * chore: adding description as a doc string * chore: updating changeset entry * chore: updating operation attribute descriptions * chore: updating operation_type attribute to operation_source * chore: skipping request from instrumentation * chore: fixing clippy issues * re-running nix build * updating unit test snapshot * chore: fixing toml formatting issues * test: removing asserts on constants * chore: format issues * test: adjusting unit test to not use local envar * revert: undoing accidental commit * test: removing unnecessary assert
1 parent 7ec1208 commit cd54f70

File tree

12 files changed

+687
-43
lines changed

12 files changed

+687
-43
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
### feat: adding ability to omit attributes for traces and metrics - @alocay PR #358
2+
3+
Adding ability to configure which attributes are omitted from telemetry traces and metrics.
4+
5+
1. Using a Rust build script (`build.rs`) to auto-generate telemetry attribute code based on the data found in `telemetry.toml`.
6+
2. Utilizing an enum for attributes so typos in the config file raise an error.
7+
3. Omitting trace attributes by filtering it out in a custom exporter.
8+
4. Omitting metric attributes by indicating which attributes are allowed via a view.
9+
5. Created `telemetry_attributes.rs` to map `TelemetryAttribute` enum to a OTEL `Key`.
10+
11+
The `telemetry.toml` file includes attributes (both for metrics and traces) as well as list of metrics gathered. An example would look like the following:
12+
```
13+
[attributes.apollo.mcp]
14+
my_attribute = "Some attribute info"
15+
16+
[metrics.apollo.mcp]
17+
some.count = "Some metric count info"
18+
```
19+
This would generate a file that looks like the following:
20+
```
21+
/// All TelemetryAttribute values
22+
pub const ALL_ATTRS: &[TelemetryAttribute; 1usize] = &[
23+
TelemetryAttribute::MyAttribute
24+
];
25+
#[derive(Debug, ::serde::Deserialize, ::schemars::JsonSchema,, Clone, Eq, PartialEq, Hash, Copy)]
26+
pub enum TelemetryAttribute {
27+
///Some attribute info
28+
#[serde(alias = "my_attribute")]
29+
MyAttribute,
30+
}
31+
impl TelemetryAttribute {
32+
/// Supported telemetry attribute (tags) values
33+
pub const fn as_str(&self) -> &'static str {
34+
match self {
35+
TelemetryAttribute::MyAttribute => "apollo.mcp.my_attribute",
36+
}
37+
}
38+
}
39+
#[derive(Debug, ::serde::Deserialize, ::schemars::JsonSchema,, Clone, Eq, PartialEq, Hash, Copy)]
40+
pub enum TelemetryMetric {
41+
///Some metric count info
42+
#[serde(alias = "some.count")]
43+
SomeCount,
44+
}
45+
impl TelemetryMetric {
46+
/// Converts TelemetryMetric to &str
47+
pub const fn as_str(&self) -> &'static str {
48+
match self {
49+
TelemetryMetric::SomeCount => "apollo.mcp.some.count",
50+
}
51+
}
52+
}
53+
```
54+
An example configuration that omits `tool_name` attribute for metrics and `request_id` for tracing would look like the following:
55+
```
56+
telemetry:
57+
exporters:
58+
metrics:
59+
otlp:
60+
endpoint: "http://localhost:4317"
61+
protocol: "grpc"
62+
omitted_attributes:
63+
- tool_name
64+
tracing:
65+
otlp:
66+
endpoint: "http://localhost:4317"
67+
protocol: "grpc"
68+
omitted_attributes:
69+
- request_id
70+
```

Cargo.lock

Lines changed: 62 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/apollo-mcp-server/Cargo.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ license-file.workspace = true
66
repository.workspace = true
77
rust-version.workspace = true
88
version.workspace = true
9+
build = "build.rs"
910

1011
default-run = "apollo-mcp-server"
1112

@@ -42,7 +43,9 @@ opentelemetry-otlp = { version = "0.30.0", features = [
4243
opentelemetry-resource-detectors = "0.9.0"
4344
opentelemetry-semantic-conventions = "0.30.0"
4445
opentelemetry-stdout = "0.30.0"
45-
opentelemetry_sdk = "0.30.0"
46+
opentelemetry_sdk = { version = "0.30.0", features = [
47+
"spec_unstable_metrics_views",
48+
] }
4649
regex = "1.11.1"
4750
reqwest-middleware = "0.4.2"
4851
reqwest-tracing = { version = "0.5.8", features = ["opentelemetry_0_30"] }
@@ -66,6 +69,7 @@ tracing-opentelemetry = "0.31.0"
6669
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
6770
tracing.workspace = true
6871
url.workspace = true
72+
async-trait = "0.1.89"
6973

7074
[dev-dependencies]
7175
chrono = { version = "0.4.41", default-features = false, features = ["now"] }
@@ -78,6 +82,14 @@ tokio.workspace = true
7882
tower = "0.5.2"
7983
tracing-test = "0.2.5"
8084

85+
[build-dependencies]
86+
cruet = "0.15.0"
87+
prettyplease = "0.2.37"
88+
quote = "1.0.40"
89+
serde.workspace = true
90+
syn = "2.0.106"
91+
toml = "0.9.5"
92+
8193
[lints]
8294
workspace = true
8395

0 commit comments

Comments
 (0)