Repository navigation
Derive runtime metrics from invocation spans #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9290cf7
24aa6dc
36f8fb2
1650db3
53f89b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| The `signal_to_metrics` connector derives the `gen_ai.invoke_agent.duration` metric from the `invoke_agent` spans that the `kagent` runtime emits. That runtime does not record the metric itself. | ||
|
|
||
| The connector reads the spans before any sampling in the collector. Its conditions skip the two A2A server instrumentation scopes. A span from those scopes carries the `invoke_agent` operation only when that layer also records the metric, so skipping the scopes prevents a double count. | ||
|
|
||
| The connector emits delta histograms, and the Prometheus exporter accepts only cumulative ones. The `delta_to_cumulative` processor converts them. Without it, the exporter logs `Dropped misaligned histogram datapoint` and keeps one point per series, so the duration queries return almost nothing. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -257,6 +257,35 @@ Install a collector that receives OTLP on ports `4317` for gRPC and `4318` for H | |
| endpoint: 0.0.0.0:4318 | ||
| processors: | ||
| batch: {} | ||
| delta_to_cumulative: {} | ||
| connectors: | ||
| signal_to_metrics: | ||
| spans: | ||
| - name: gen_ai.invoke_agent.duration | ||
| description: The duration of one agent invocation, derived from its span. | ||
| unit: s | ||
| conditions: | ||
| - span.attributes["gen_ai.operation.name"] == "invoke_agent" and instrumentation_scope.name != "github.com/kagent-dev/kagent/go/adk/pkg/a2a/server" and instrumentation_scope.name != "kagent.core.a2a" | ||
| histogram: | ||
| buckets: [0.5, 1, 2, 5, 10, 30, 60, 120, 300] | ||
| value: Seconds(span.end_time - span.start_time) | ||
| attributes: | ||
| - key: gen_ai.agent.name | ||
| optional: true | ||
| - key: gen_ai.request.model | ||
| optional: true | ||
| - key: error.type | ||
| optional: true | ||
| include_resource_attributes: | ||
| - key: service.name | ||
| - key: service.namespace | ||
| optional: true | ||
| - key: service.version | ||
| optional: true | ||
| - key: kagent.runtime | ||
| optional: true | ||
| - key: gen_ai.main_agent.id | ||
| optional: true | ||
| exporters: | ||
| otlp_grpc/tempo: | ||
| endpoint: tempo.telemetry.svc.cluster.local:4317 | ||
|
|
@@ -273,20 +302,22 @@ Install a collector that receives OTLP on ports `4317` for gRPC and `4318` for H | |
| traces: | ||
| receivers: [otlp] | ||
| processors: [batch] | ||
| exporters: [otlp_grpc/tempo] | ||
| exporters: [signal_to_metrics, otlp_grpc/tempo] | ||
| logs: | ||
| receivers: [otlp] | ||
| processors: [batch] | ||
| exporters: [otlp_http/loki] | ||
| metrics: | ||
| receivers: [otlp] | ||
| processors: [batch] | ||
| receivers: [otlp, signal_to_metrics] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blocking: This has the same delta-into-
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed here too. This pipeline now declares |
||
| processors: [delta_to_cumulative, batch] | ||
| exporters: [prometheus] | ||
| EOF | ||
| ``` | ||
|
|
||
| The `resource_to_telemetry_conversion` setting copies OTel resource attributes, such as the service name, onto each metric as labels. Without it, you cannot tell which Agent Substrate component reported a metric. | ||
|
|
||
| {{< reuse "kagent-docs/snippets/signal-to-metrics-connector.md" >}} | ||
|
|
||
| 2. Create a ServiceMonitor so that Prometheus scrapes the metrics that the collector serves. | ||
| ```yaml | ||
| kubectl apply -f - <<EOF | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking: The
prometheusexporter drops almost all of the derived metric.I ran this collector config on
otel/opentelemetry-collector-contrib:0.159.0and sent it syntheticinvoke_agentspans withtelemetrygen. The connector emits delta histograms with a zero start timestamp, as the debug exporter shows:The
prometheusexporter accepts only cumulative data, so it logsDropped misaligned histogram datapointand keeps only the first point. 20 traces (40 matching spans) ended atgen_ai_invoke_agent_duration_seconds_count 2, with 40 drop warnings. The p95 query inmetrics.mdwould therefore return almost nothing. The upstream reference config does not hit this, because it exports over OTLP.Adding a
deltatocumulativeprocessor to the metrics pipeline was not a simple fix in my test._countkept rising after the spans stopped (100, then 346, for 3 traces). Could you or a kagent maintainer pick a fix and test it? The same pipeline is inotel-stack.mdline 310.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reproduced and fixed. Thank you for the precise repro — the drop count made this quick to confirm.
On a 1.37 kind cluster with chart 0.172.0 (which ships
otel/opentelemetry-collector-contrib:0.159.0, the same build you used), 20 telemetrygen traces carryinggen_ai.operation.name=invoke_agentproduced 38Dropped misaligned histogram datapointwarnings andgen_ai_invoke_agent_duration_seconds_count 2, exactly as you saw.Adding a
deltatocumulativeprocessor to the metrics pipeline fixes it. Same config, same 20 traces: zero drop warnings and_count 40, flat across twelve samples over three minutes. A second batch of 20 took it to exactly 80, so it accumulates correctly rather than creeping. I could not reproduce the runaway_countyou hit — I also tried both[deltatocumulative, batch]and[batch, deltatocumulative], and both give 40.Both guides now declare the processor and put it in the metrics pipeline, and the shared snippet explains why it is there.
You were also right that the reference config does not hit this: it exports to
otlp/backend, so delta passes straight through.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One correction to my reply above: the processor is spelled
delta_to_cumulative, and that is what both guides now use.deltatocumulativeis a deprecated alias. It works, but a collector logs"deltatocumulative" alias is deprecated; use "delta_to_cumulative" insteadon startup. Re-tested with the current spelling on the chart's own 0.159.0:_count 40, zero drops, and no deprecation warning.