Skip to content

feat(tel): implement otel sink - #1888

Merged
Hweinstock merged 14 commits into
aws:refactorfrom
Hweinstock:feat/otel-sink
Aug 14, 2026
Merged

feat(tel): implement otel sink#1888
Hweinstock merged 14 commits into
aws:refactorfrom
Hweinstock:feat/otel-sink

Conversation

@Hweinstock

@Hweinstock Hweinstock commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Problem

The AgentCore CLI is not currently publishing telemetry to our collector.

Solution

  • otel sdk requires the resource attributes separated from the metric attributes (even though they are merged on the request) so we explicitly inject those into each sink.
  • implement an otel histogram metric sink. We use histogram because our values represent duration, so histogram gives us count, and distributions over the values in a single instrument.

Testing

  • run our collector locally, and override local endpoint to point to it. Then verified metrics hit cloudwatch in dev account. (Requires one small backend change that is already in the pipeline).
  • added a unit test that spins up a local server, and verifies it only receives request when telemetry is enabled, and requests match otel format.

@github-actions github-actions Bot added the agentcore-harness-reviewing AgentCore Harness review in progress label Jul 31, 2026
@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label Jul 31, 2026
@codecov-commenter

codecov-commenter commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.48485% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.70%. Comparing base (7e29eda) to head (6806436).
⚠️ Report is 12 commits behind head on refactor.

Files with missing lines Patch % Lines
src/telemetry/otelSink.tsx 98.07% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           refactor    #1888   +/-   ##
=========================================
  Coverage     96.69%   96.70%           
=========================================
  Files           291      292    +1     
  Lines         16012    16068   +56     
=========================================
+ Hits          15483    15538   +55     
- Misses          529      530    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Hweinstock

Copy link
Copy Markdown
Contributor Author

^ the line missing coverage is getName() on the collector sink.

@Hweinstock Hweinstock changed the title 0feat(tel): implement otel sink feat(tel): implement otel sink Jul 31, 2026
@Hweinstock
Hweinstock marked this pull request as ready for review July 31, 2026 19:22

async shutdown(): Promise<void> {
try {
await this.meterProvider.forceFlush({ timeoutMillis: this.flushTimeoutMs });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

outside this try block, there is meterProvider.shutdown() which also flushes the metric again.

https://opentelemetry.io/docs/specs/otel/metrics/sdk/#shutdown

can we ensure one export somehow?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This method provides a way for provider to do any cleanup required.

Shutdown MUST be called only once for each MeterProvider instance. After the call to Shutdown, subsequent attempts to get a Meter are not allowed. SDKs SHOULD return a valid no-op Meter for these calls, if possible.

Shutdown SHOULD provide a way to let the caller know whether it succeeded, failed or timed out.

Shutdown SHOULD complete or abort within some timeout. Shutdown MAY be implemented as a blocking API or an asynchronous API which notifies the caller via a callback or an event. [OpenTelemetry SDK](https://opentelemetry.io/docs/specs/otel/overview/#sdk) authors MAY decide if they want to make the shutdown timeout configurable.

Shutdown MUST be implemented at least by invoking Shutdown on all registered [MetricReader](https://opentelemetry.io/docs/specs/otel/metrics/sdk/#metricreader) and [MetricExporter](https://opentelemetry.io/docs/specs/otel/metrics/sdk/#metricexporter) instances.

from https://opentelemetry.io/docs/specs/otel/metrics/sdk/#shutdown.

I don't see any explicit lines in the protocol linked for shutdown that it also flushes. Based on some testing, I think it does internally, but I think its safer to make that behavior explicit. If we flush twice, its a no-op anyway.

Comment thread src/telemetry/client.tsx

if (globalConfig.telemetry.enabled)
metricSinks.push(
new OtelHistogramSink({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it seems like a wrong/malformed endpoint makes getMetricSinks() reject, and shutdown() propagates that rejection, erroring out in the CLI command. Is that understanding correct? can we make it best-effort?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we (the dev team) should be the only ones modifying the endpoint for testing purposes. In which case, I think the ideal behavior is that we reject early.

If a user decides to go into the global config and add an invalid override, I think rejecting is reasonable.

notgitika
notgitika previously approved these changes Aug 1, 2026

@notgitika notgitika left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGMT

Comment thread src/telemetry/otelSink.tsx Outdated
try {
await this.meterProvider.forceFlush({ timeoutMillis: this.flushTimeoutMs });
} catch (e) {
const error = e instanceof Error ? e : new Error(String(e));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want to use our AgentCoreError.fromError() here instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think that makes sense to ensure its consistent.

@Hweinstock

Copy link
Copy Markdown
Contributor Author

slack failure appears unrelated.

Configure AWS credentials (central secrets reader)
1m 0s
Run aws-actions/configure-aws-credentials@v6
  Retry validateCredentials: attempt 1 of 12 failed: Credentials could not be loaded, please check your action inputs: Could not load credentials from any providers. Retrying after 23ms.

notgitika
notgitika previously approved these changes Aug 12, 2026
resource: resourceFromAttributes(config.resourceAttributes),
readers: [
new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I may be missing whether inheriting the caller's OTEL configuration is intentional, but OTLPMetricExporter reads OTEL_EXPORTER_OTLP_HEADERS and OTEL_EXPORTER_OTLP_METRICS_HEADERS when headers is omitted. I set dummy authorization and x-api-key values and confirmed both were forwarded to the configured collector. A user running the CLI in an environment configured for another OTLP backend could therefore send those credentials to telemetry.agentcore.aws.dev. Would passing headers: {} here make sense?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nice catch, was not aware of these environment variables. Was going to add this as a follow-up, but let me inject the right header now to avoid this behavior.

.child({ metricName, metricValue: value, metricAttributes: attributes })
.info(`sending telemetry metric to collector`);

this.getHistogram(metricName).record(value, attributes);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the resource attributes are still ending up in both places. InMemoryMetricEvent.emit() merges resourceAttributes into the sink attributes, then this line records that merged map after the provider already registered the same fields with resourceFromAttributes. In a local OTLP capture, all eight resource keys appeared under both resource.attributes and histogram.dataPoints[].attributes. Since the goal here is to separate resource and metric attributes, would it make sense for the sink contract to receive only metric attributes, with FileSystemSink composing its JSONL entry from its configured resource attributes? The test could also assert that resource keys are absent from the datapoint. This is really a low finding and could always be changed in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch, I think removing is the right call to simplify.

aidandaly24
aidandaly24 previously approved these changes Aug 12, 2026
@Hweinstock
Hweinstock dismissed stale reviews from aidandaly24 and notgitika via 7e9a97e August 13, 2026 13:05
@notgitika

Copy link
Copy Markdown
Contributor

looks good to me!

@Hweinstock
Hweinstock merged commit 01eb60b into aws:refactor Aug 14, 2026
8 of 11 checks passed
@Hweinstock
Hweinstock deleted the feat/otel-sink branch August 14, 2026 19:09
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.

5 participants