Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function extractAttributesFromMapping(data: any, mapping: AttributeMap):
continue;
}

if (typeof value !== 'string') {
if (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean') {
value = safeSerialize(value);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/attributes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('attributes helpers', () => {
const data = { a: 1, b: 'str', c: { foo: 'bar' } };
const mapping = { x: 'a', y: 'b', z: 'c' };
expect(extractAttributesFromMapping(data, mapping)).toEqual({
x: '1',
x: 1,
y: 'str',
z: '{"foo":"bar"}'
});
Expand Down
3 changes: 2 additions & 1 deletion tests/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ describe('InstrumentationBase', () => {
});

it('runtime targeting runs setup only once', () => {
const inst = new RuntimeInstrumentation('n','v',{});
const client: any = { config: { serviceName: 'svc' } };
const inst = new RuntimeInstrumentation(client);
inst.setupRuntimeTargeting();
expect(inst.setup).toHaveBeenCalledTimes(1);
inst.setupRuntimeTargeting();
Expand Down
32 changes: 23 additions & 9 deletions tests/openai-converters.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { convertGenerationSpan } from '../src/instrumentation/openai-agents/generation';
import { convertAgentSpan } from '../src/instrumentation/openai-agents/agent';
import { convertFunctionSpan } from '../src/instrumentation/openai-agents/function';
import { convertResponseSpan, convertEnhancedResponseSpan, createEnhancedResponseSpanData } from '../src/instrumentation/openai-agents/response';
import { convertResponseSpan } from '../src/instrumentation/openai-agents/response';
import { convertHandoffSpan } from '../src/instrumentation/openai-agents/handoff';
import { convertCustomSpan } from '../src/instrumentation/openai-agents/custom';
import { convertGuardrailSpan } from '../src/instrumentation/openai-agents/guardrail';
Expand All @@ -10,6 +10,28 @@ import { convertMCPListToolsSpan } from '../src/instrumentation/openai-agents/mc
import { getSpanName, getSpanKind, getSpanAttributes } from '../src/instrumentation/openai-agents/attributes';
import { SpanKind } from '@opentelemetry/api';

// Minimal helpers mirroring removed SDK exports
function createEnhancedResponseSpanData(request: any, response: any) {
return {
type: 'response',
response_id: response.responseId,
_input: request.input,
_response: {
id: response.responseId,
model: request.model,
usage: {
input_tokens: response.usage?.inputTokens,
output_tokens: response.usage?.outputTokens,
total_tokens: response.usage?.totalTokens,
},
},
} as any;
}

function convertEnhancedResponseSpan(data: any) {
return convertResponseSpan(data);
}

const genData = {
type: 'generation',
model: { model: 'gpt4' },
Expand All @@ -36,14 +58,6 @@ describe('OpenAI converters', () => {
expect(convertSpeechSpan({ type:'speech', output:{data:'d',format:'f'}, model:'m'} as any)['audio.output.data']).toBe('d');
expect(convertSpeechGroupSpan({ type:'speech_group', input:'i'} as any)['audio.input.data']).toBe('i');
expect(convertMCPListToolsSpan({ type:'mcp_tools', server:'s', result:['x'] } as any)['mcp.server']).toBe('s');
expect(convertResponseSpan({ type:'response', response_id:'r' } as any)['response.id']).toBe('r');
});

it('enhances response data', () => {
const enhanced = createEnhancedResponseSpanData({ model:'m', input:[{type:'message', role:'user', content:'c'}] }, { responseId:'id', usage:{ inputTokens:1, outputTokens:2, totalTokens:3 } });
const attrs = convertEnhancedResponseSpan(enhanced);
expect(attrs['gen_ai.prompt.0.content']).toBe('c');
expect(attrs['gen_ai.usage.total_tokens']).toBe('3');
});

it('getSpanName and kind', () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ describe('InstrumentationRegistry', () => {
AVAILABLE_INSTRUMENTORS: [RuntimeInst, SimpleInst]
}));
const { InstrumentationRegistry } = require('../src/instrumentation/registry');
const registry = new InstrumentationRegistry();
const client: any = { config: { serviceName: 'svc' } };
const registry = new InstrumentationRegistry(client);
registry.initialize();
expect(registry.getAvailable().length).toBe(2);
const active = registry.getActiveInstrumentors('svc');
Expand Down