Skip to content

feat(agents): support OpenTelemetry metrics#1381

Open
Fant1k34 wants to merge 11 commits intodevelopfrom
ndukin/add-open-telemetry-metric
Open

feat(agents): support OpenTelemetry metrics#1381
Fant1k34 wants to merge 11 commits intodevelopfrom
ndukin/add-open-telemetry-metric

Conversation

@Fant1k34
Copy link
Copy Markdown

@Fant1k34 Fant1k34 commented Jan 19, 2026

Motivation and Context

PR introduces metrics support based on OpenTelemetry specification. Such metrics allow their listeners observe the behaviour of agent in run-time. All changes are done within OpenTelemetry feature

Link to issue

Added configuration:

  • addMeterExporter(MetricExporter) -- function within OpenTelemetry feature that accept MetricExporter and sent library metrics via such exporter

Example of OpenTelemetry feature configuration:

install(OpenTelemetry) {
    setServiceInfo(
        "calculator",
        "0.0.1"
    )
    addResourceAttributes(
        mapOf(AttributeKey.stringKey("service.instance.id") to "run-1")
    )
    addMeterExporter(
        OtlpGrpcMetricExporter.builder()
            .setEndpoint("http://localhost:17011")
            .setTimeout(1, TimeUnit.SECONDS)
            .build()
        )
    }

Added metrics:

  • gen_ai.client.token.usage -- see here
  • gen_ai.client.operation.duration -- see here
  • gen_ai.client.tool.count -- custom metric allows observe tool calls and their statuses

Visualisation (via OpenTelemetry plugin):
telegram-cloud-photo-size-2-5438313832905380635-y
image

Breaking Changes


Type of the changes

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tests improvement
  • Refactoring
  • CI/CD changes
  • Dependencies update

Checklist

  • The pull request has a description of the proposed change
  • I read the Contributing Guidelines before opening the pull request
  • The pull request uses develop as the base branch
  • Tests for the changes have been added
  • All new and existing tests passed
Additional steps for pull requests adding a new feature
  • An issue describing the proposed change exists
  • The pull request includes a link to the issue
  • The change was discussed and approved in the issue
  • Docs have been added / updated

@Fant1k34 Fant1k34 requested a review from sdubov January 20, 2026 16:44
@Fant1k34 Fant1k34 changed the title [WIP] Ndukin/add open telemetry metric Ndukin/add open telemetry metric Jan 21, 2026
@Fant1k34 Fant1k34 changed the title Ndukin/add open telemetry metric Add open telemetry metric support in Koog Jan 21, 2026
Copy link
Copy Markdown
Collaborator

@sdubov sdubov left a comment

Choose a reason for hiding this comment

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

I like the consistency for current metrics support implementation. Thank you. Please check my comments about some metrics implementation details.

@Fant1k34 Fant1k34 requested review from egorklimov and sdubov February 3, 2026 14:25
@Fant1k34 Fant1k34 requested a review from egorklimov February 5, 2026 14:21
@Fant1k34 Fant1k34 requested a review from egorklimov February 5, 2026 15:53
Copy link
Copy Markdown
Collaborator

@sdubov sdubov left a comment

Choose a reason for hiding this comment

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

As we discussed, I have two concerns here:

  1. restricToolNameCardinality config which I found a bit confusing. As I noticed, I would implement this as an extension for a metric adapter (similar to the span adapter).
  2. Single responsibility for MetricCollector class. I would prefer it to be able to track any metric and help to create it if needed (keep the timestamp for a start event if needed for now).

Other than that, looks good for me. We can address some of those questions later in a further commits. For now, I will approve this one to not block the development.

@Fant1k34 Fant1k34 changed the title Add open telemetry metric support in Koog feat(metrics): add open telemetry metric support in Koog Feb 11, 2026
@Fant1k34 Fant1k34 changed the title feat(metrics): add open telemetry metric support in Koog feat(koog-agents): add open telemetry metric support in Koog Feb 11, 2026
@Fant1k34 Fant1k34 force-pushed the ndukin/add-open-telemetry-metric branch from 90369c1 to a081034 Compare February 12, 2026 10:06
@egorklimov egorklimov force-pushed the ndukin/add-open-telemetry-metric branch from 3c8b58a to cd1a58d Compare February 17, 2026 17:09
@egorklimov egorklimov changed the title feat(koog-agents): add open telemetry metric support in Koog feat(agents): add open telemetry metric support in Koog Feb 17, 2026
@egorklimov egorklimov changed the title feat(agents): add open telemetry metric support in Koog feat(agents): support OpenTelemetry metrics Feb 17, 2026
@egorklimov egorklimov force-pushed the ndukin/add-open-telemetry-metric branch from 04ce47e to 4535497 Compare February 17, 2026 17:46
@egorklimov egorklimov force-pushed the ndukin/add-open-telemetry-metric branch from 49129e2 to fbba4e9 Compare March 19, 2026 16:58
@Fant1k34 Fant1k34 force-pushed the ndukin/add-open-telemetry-metric branch from bcd52c2 to 7707721 Compare April 11, 2026 16:48
@Fant1k34 Fant1k34 requested a review from egorklimov April 11, 2026 17:29
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