Skip to content
Draft
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 packages/core/src/tracing/google-genai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function addPrivateRequestAttributes(
if (operationName === 'embeddings') {
const contents = params.contents;
if (contents != null) {
span.setAttribute(GEN_AI_EMBEDDINGS_INPUT, typeof contents === 'string' ? contents : JSON.stringify(contents));
span.setAttribute(GEN_AI_EMBEDDINGS_INPUT, stringify(contents, String));
}
return;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/tracing/langchain/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
GEN_AI_REQUEST_ENCODING_FORMAT_ATTRIBUTE,
} from '../ai/gen-ai-attributes';
import { resolveAIRecordingOptions } from '../ai/utils';
import { stringify } from '../../utils/string';
import { LANGCHAIN_ORIGIN } from './constants';
import type { LangChainOptions } from './types';

Expand Down Expand Up @@ -73,7 +74,7 @@ export function _INTERNAL_getLangChainEmbeddingsSpanOptions(
const modelName = attributes[GEN_AI_REQUEST_MODEL] || 'unknown';

if (recordInputs && input != null) {
attributes[GEN_AI_EMBEDDINGS_INPUT] = typeof input === 'string' ? input : JSON.stringify(input);
attributes[GEN_AI_EMBEDDINGS_INPUT] = stringify(input, String);
}

return {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/tracing/langchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '
import { SPAN_STATUS_ERROR } from '../../tracing';
import { startSpanManual } from '../../tracing/trace';
import type { Span, SpanAttributeValue } from '../../types/span';
import { stringify } from '../../utils/string';
import {
GEN_AI_OPERATION_NAME,
GEN_AI_REQUEST_MODEL,
Expand Down Expand Up @@ -327,7 +328,7 @@ export function createLangChainCallbackHandler(options: LangChainOptions = {}):
const content =
outputObj && typeof outputObj === 'object' && 'content' in outputObj ? outputObj.content : output;
span.setAttributes({
[GEN_AI_TOOL_CALL_RESULT]: typeof content === 'string' ? content : JSON.stringify(content),
[GEN_AI_TOOL_CALL_RESULT]: stringify(content, String),
});
}
exitSpan(runId);
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/tracing/openai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ export function addRequestAttributes(
return;
}

// Store strings as-is, arrays/objects as JSON
span.setAttribute(GEN_AI_EMBEDDINGS_INPUT, typeof input === 'string' ? input : JSON.stringify(input));
span.setAttribute(GEN_AI_EMBEDDINGS_INPUT, stringify(input, String));
return;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/tracing/workers-ai/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function addRequestAttributes(
return;
}

span.setAttribute(GEN_AI_EMBEDDINGS_INPUT, typeof text === 'string' ? text : JSON.stringify(text));
span.setAttribute(GEN_AI_EMBEDDINGS_INPUT, stringify(text, String));
return;
}

Expand Down Expand Up @@ -168,7 +168,7 @@ export function setOutputMessagesAttribute(
type: 'tool_call',
id: call.id,
name,
arguments: typeof args === 'string' ? args : JSON.stringify(args ?? {}),
arguments: stringify(args ?? {}, String),
});
}
}
Expand Down
Loading