Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/full-signs-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inkeep/agents-api": patch
---

adding app.id to span attributes
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: changelog messages should start with a capitalized action verb per the repo conventions (e.g. "Add app.id to span attributes").

Suggested change
adding app.id to span attributes
Add `app.id` to span attributes

7 changes: 7 additions & 0 deletions agents-api/src/middleware/runAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
verifySlackUserToken,
verifyTempToken,
} from '@inkeep/agents-core';
import { trace } from '@opentelemetry/api';
import { createMiddleware } from 'hono/factory';
import { HTTPException } from 'hono/http-exception';
import { errors, jwtVerify } from 'jose';
Expand Down Expand Up @@ -708,6 +709,9 @@ async function runApiKeyAuthHandler(
c.set('executionContext', buildExecutionContext(createDevContext(reqData), reqData));
}

if (reqData.appId && attempt.authResult) {
trace.getActiveSpan()?.setAttribute('app.id', reqData.appId);
Copy link
Contributor

Choose a reason for hiding this comment

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

💭 Consider: Add app.id to SPAN_KEYS constants

Issue: The new 'app.id' attribute is defined as a string literal, while the codebase has an established pattern of centralizing span attribute keys in SPAN_KEYS in packages/agents-core/src/constants/otel-attributes.ts.

Why: Centralizing attribute names helps maintain a consistent telemetry schema and makes it easier to audit what attributes are being emitted. However, I note the codebase has some mixed patterns (e.g., chat.ts also uses inline strings like 'user.type'), so this is a suggestion rather than a requirement.

Fix: Optionally add to otel-attributes.ts:

APP_ID: 'app.id',

Then import and use SPAN_KEYS.APP_ID here.

Refs:

}
Comment on lines +712 to +714
Copy link
Contributor

Choose a reason for hiding this comment

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

The dev-environment guard checks attempt.authResult in addition to reqData.appId, but the production path (line 764) only checks reqData.appId. In the dev fallback branch (line 702–709), when appId is present but auth fails, the span won't get the attribute — even though the request is clearly associated with that app.

Since reqData.appId is the only thing that matters for attributing the span, consider dropping the attempt.authResult check to match the production path:

Suggested change
if (reqData.appId && attempt.authResult) {
trace.getActiveSpan()?.setAttribute('app.id', reqData.appId);
}
if (reqData.appId) {
trace.getActiveSpan()?.setAttribute('app.id', reqData.appId);
}

await next();
return;
}
Expand Down Expand Up @@ -757,6 +761,9 @@ async function runApiKeyAuthHandler(
);

c.set('executionContext', buildExecutionContext(attempt.authResult, reqData));
if (reqData.appId) {
trace.getActiveSpan()?.setAttribute('app.id', reqData.appId);
}
await next();
}

Expand Down
Loading