|
| 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 | +``` |
0 commit comments