Skip to content

Commit eb6211f

Browse files
authored
fix(sdk): versions on workflows & tasks (#353)
1 parent 75c68ce commit eb6211f

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

packages/ai-semantic-conventions/src/SemanticAttributes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const SpanAttributes = {
5151
TRACELOOP_SPAN_KIND: "traceloop.span.kind",
5252
TRACELOOP_WORKFLOW_NAME: "traceloop.workflow.name",
5353
TRACELOOP_ENTITY_NAME: "traceloop.entity.name",
54+
TRACELOOP_ENTITY_VERSION: "traceloop.entity.version",
5455
TRACELOOP_ASSOCIATION_PROPERTIES: "traceloop.association.properties",
5556
TRACELOOP_ENTITY_INPUT: "traceloop.entity.input",
5657
TRACELOOP_ENTITY_OUTPUT: "traceloop.entity.output",

packages/traceloop-sdk/src/lib/tracing/decorators.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Telemetry } from "../telemetry/telemetry";
1414

1515
export type DecoratorConfig = {
1616
name: string;
17+
version?: number;
1718
associationProperties?: { [name: string]: string };
1819
traceContent?: boolean;
1920
inputParameters?: unknown[];
@@ -26,6 +27,7 @@ function withEntity<
2627
type: TraceloopSpanKindValues,
2728
{
2829
name,
30+
version,
2931
associationProperties,
3032
traceContent: overrideTraceContent,
3133
inputParameters,
@@ -69,6 +71,10 @@ function withEntity<
6971
span.setAttribute(SpanAttributes.TRACELOOP_SPAN_KIND, type);
7072
span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_NAME, name);
7173

74+
if (version) {
75+
span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_VERSION, version);
76+
}
77+
7278
if (shouldSendTraces()) {
7379
try {
7480
const input = inputParameters ?? args;

packages/traceloop-sdk/test/decorators.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ describe("Test SDK Decorators", () => {
147147

148148
it("should create spans for workflows using decoration syntax", async () => {
149149
class TestOpenAI {
150-
@traceloop.workflow({ name: "sample_chat" })
150+
@traceloop.workflow({ name: "sample_chat", version: 2 })
151151
async chat(things: Map<string, string>) {
152152
const generations: Map<string, string> = new Map();
153153
for await (const [key, value] of things) {
@@ -195,6 +195,10 @@ describe("Test SDK Decorators", () => {
195195
workflowSpan.attributes[`${SpanAttributes.TRACELOOP_ENTITY_NAME}`],
196196
"sample_chat",
197197
);
198+
assert.strictEqual(
199+
workflowSpan.attributes[`${SpanAttributes.TRACELOOP_ENTITY_VERSION}`],
200+
2,
201+
);
198202
assert.strictEqual(
199203
workflowSpan.attributes[`${SpanAttributes.TRACELOOP_ENTITY_INPUT}`],
200204
JSON.stringify({

0 commit comments

Comments
 (0)