Skip to content

Commit bf941c0

Browse files
authored
fix(cloudflare): Use gen_ai.agent.name for class names (#22911)
The `cloudflare.*` names were shipped by accident and there is a good alternative for it
1 parent 29266eb commit bf941c0

5 files changed

Lines changed: 5 additions & 17 deletions

File tree

dev-packages/e2e-tests/test-applications/cloudflare-agent/tests/callable.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ test('creates an rpc span named after the @callable() method', async ({ page, ba
181181
description: 'greet',
182182
origin: 'auto.faas.cloudflare.agents',
183183
data: expect.objectContaining({
184-
'cloudflare.agent.class': 'MyBaseAgent',
185-
'cloudflare.agent.name': 'user-123',
184+
'gen_ai.agent.name': 'MyBaseAgent',
186185
}),
187186
}),
188187
);

dev-packages/e2e-tests/test-applications/cloudflare-agent/tests/chat-rpc.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ test('creates an rpc span for a @callable() invocation on an AIChatAgent', async
2222
op: 'rpc',
2323
description: 'greet',
2424
origin: 'auto.faas.cloudflare.agents',
25-
data: expect.objectContaining({
26-
'cloudflare.agent.name': AGENT_INSTANCE,
27-
}),
2825
}),
2926
);
3027
});

dev-packages/e2e-tests/test-applications/cloudflare-autoinstrument/tests/autoinstrument.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ for (const { title, binding, agentClass } of [
7474
// confirms the wrapper landed on the user's real class. Matched loosely
7575
// because the transform renames the class it wraps to
7676
// `__SENTRY_ORIGINAL_<name>__` and the bundler infers that name.
77-
'cloudflare.agent.class': expect.stringContaining(agentClass),
78-
'cloudflare.agent.name': instance,
77+
'gen_ai.agent.name': expect.stringContaining(agentClass),
7978
}),
8079
}),
8180
);

packages/cloudflare/src/instrumentations/agents/types.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import { GEN_AI_AGENT_NAME } from '@sentry/conventions/attributes';
12
import { getCurrentScope } from '@sentry/core';
23

34
export const AGENT_SPAN_ORIGIN = 'auto.faas.cloudflare.agents';
4-
export const AGENT_CLASS_ATTRIBUTE = 'cloudflare.agent.class';
5-
export const AGENT_NAME_ATTRIBUTE = 'cloudflare.agent.name';
65

76
/**
87
* The subset of the `agents` `Agent` instance internals that we instrument. These are runtime
@@ -40,12 +39,7 @@ export function getAgentAttributes(instance: AgentInternals): Record<string, str
4039

4140
const agentClass = instance._ParentClass?.name;
4241
if (typeof agentClass === 'string' && agentClass) {
43-
attributes[AGENT_CLASS_ATTRIBUTE] = agentClass;
44-
}
45-
46-
const agentName = instance.name;
47-
if (typeof agentName === 'string' && agentName) {
48-
attributes[AGENT_NAME_ATTRIBUTE] = agentName;
42+
attributes[GEN_AI_AGENT_NAME] = agentClass;
4943
}
5044

5145
return attributes;

packages/cloudflare/test/instrumentCloudflareAgent.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ describe('instrumentCloudflareAgent', () => {
8686
op: 'rpc',
8787
origin: 'auto.faas.cloudflare.agents',
8888
data: expect.objectContaining({
89-
'cloudflare.agent.class': 'MyAgent',
90-
'cloudflare.agent.name': 'instance-1',
89+
'gen_ai.agent.name': 'MyAgent',
9190
}),
9291
}),
9392
);

0 commit comments

Comments
 (0)