Skip to content

Conversation

@alocay
Copy link
Contributor

@alocay alocay commented Sep 12, 2025

Adding ability to configure which attributes are omitted from telemetry traces and metrics.

  1. Using a Rust build script (build.rs) to auto-generate telemetry attribute code based on the data found in telemetry.toml.
  2. Utilizing an enum for attributes so typos in the config file raise an error.
  3. Omitting trace attributes by filtering it out in a custom exporter.
  4. Omitting metric attributes by indicating which attributes are allowed via a view.
  5. Created telemetry_attributes.rs to map TelemetryAttribute enum to a OTEL Key.

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:

[attributes.apollo.mcp]
my_attribute = "Some attribute info"

[metrics.apollo.mcp]
some.count = "Some metric count info"

This would generate a file that looks like the following:

/// All TelemetryAttribute values
pub const ALL_ATTRS: &[TelemetryAttribute; 1usize] = &[
    TelemetryAttribute::MyAttribute
];
#[derive(Debug, ::serde::Deserialize, ::schemars::JsonSchema,, Clone, Eq, PartialEq, Hash, Copy)]
pub enum TelemetryAttribute {
    ///Some attribute info
    #[serde(alias = "my_attribute")]
    MyAttribute,
}
impl TelemetryAttribute {
    /// Supported telemetry attribute (tags) values
    pub const fn as_str(&self) -> &'static str {
        match self {
            TelemetryAttribute::MyAttribute => "apollo.mcp.my_attribute",
        }
    }
}
#[derive(Debug, ::serde::Deserialize, ::schemars::JsonSchema,, Clone, Eq, PartialEq, Hash, Copy)]
pub enum TelemetryMetric {
    ///Some metric count info
    #[serde(alias = "some.count")]
    SomeCount,
}
impl TelemetryMetric {
    /// Converts TelemetryMetric to &str
    pub const fn as_str(&self) -> &'static str {
        match self {
            TelemetryMetric::SomeCount => "apollo.mcp.some.count",
        }
    }
}

An example configuration that omits tool_name attribute for metrics and request_id for tracing would look like the following:

telemetry:
  exporters:
    metrics:
      otlp:
        endpoint: "http://localhost:4317"
        protocol: "grpc"
      omitted_attributes:
        - tool_name
    tracing:
      otlp:
        endpoint: "http://localhost:4317"
        protocol: "grpc"
      omitted_attributes:
        - request_id

@apollo-librarian
Copy link

apollo-librarian bot commented Sep 12, 2025

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 2 changed, 0 removed
* (developer-tools)/apollo-mcp-server/(latest)/index.mdx
* (developer-tools)/apollo-mcp-server/(latest)/limitations.mdx

Build ID: dcc498b7fd512a9837b8c86f
Build Logs: View logs

URL: https://www.apollographql.com/docs/deploy-preview/dcc498b7fd512a9837b8c86f

@apollographql apollographql deleted a comment from github-actions bot Sep 12, 2025
@alocay alocay marked this pull request as ready for review September 12, 2025 15:08
@alocay alocay requested a review from a team as a code owner September 12, 2025 15:08
}

#[tracing::instrument(skip(self, context), fields(tool_name = request.name.as_ref(), request_id = %context.id.clone()))]
#[tracing::instrument(skip(self, context), fields(apollo.mcp.attribute.tool_name = request.name.as_ref(), apollo.mcp.attribute.request_id = %context.id.clone()))]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I have not figured out a way to use the const variables from the generated code in this fields() section.

Comment on lines +233 to +234
let mut filtering_exporter = FilteringExporter::new(mock_exporter, HashSet::new());
filtering_exporter.set_resource(&Resource::builder_empty().build());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test missing an assert? Or does not throwing an error show that it's working?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assert is within the innner set_resource call which has:

assert!(true);

It's not an amazing test but since set_resource doesn't return anything I just assert within the set_resource function and call it day. Although this isn't great since calling nothing will also pass but I could not think of another way to ensure this. If any other inner function is called, it'll fail.

@alocay alocay merged commit 65cecae into feature/telemetry Sep 16, 2025
8 checks passed
@alocay alocay deleted the allow-attribute-configuration branch September 16, 2025 15:51
swcollard pushed a commit that referenced this pull request Sep 17, 2025
* 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
swcollard pushed a commit that referenced this pull request Sep 23, 2025
* 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
swcollard pushed a commit that referenced this pull request Sep 24, 2025
* 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
@apollo-bot2 apollo-bot2 mentioned this pull request Sep 24, 2025
@DaleSeo DaleSeo mentioned this pull request Sep 24, 2025
DaleSeo pushed a commit that referenced this pull request Sep 24, 2025
* 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
DaleSeo pushed a commit that referenced this pull request Sep 24, 2025
* 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
DaleSeo pushed a commit that referenced this pull request Sep 29, 2025
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants