Skip to content

Commit

Permalink
fix(sdk): versions on workflows & tasks (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirga authored Jul 4, 2024
1 parent 75c68ce commit eb6211f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/ai-semantic-conventions/src/SemanticAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const SpanAttributes = {
TRACELOOP_SPAN_KIND: "traceloop.span.kind",
TRACELOOP_WORKFLOW_NAME: "traceloop.workflow.name",
TRACELOOP_ENTITY_NAME: "traceloop.entity.name",
TRACELOOP_ENTITY_VERSION: "traceloop.entity.version",
TRACELOOP_ASSOCIATION_PROPERTIES: "traceloop.association.properties",
TRACELOOP_ENTITY_INPUT: "traceloop.entity.input",
TRACELOOP_ENTITY_OUTPUT: "traceloop.entity.output",
Expand Down
6 changes: 6 additions & 0 deletions packages/traceloop-sdk/src/lib/tracing/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Telemetry } from "../telemetry/telemetry";

export type DecoratorConfig = {
name: string;
version?: number;
associationProperties?: { [name: string]: string };
traceContent?: boolean;
inputParameters?: unknown[];
Expand All @@ -26,6 +27,7 @@ function withEntity<
type: TraceloopSpanKindValues,
{
name,
version,
associationProperties,
traceContent: overrideTraceContent,
inputParameters,
Expand Down Expand Up @@ -69,6 +71,10 @@ function withEntity<
span.setAttribute(SpanAttributes.TRACELOOP_SPAN_KIND, type);
span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_NAME, name);

if (version) {
span.setAttribute(SpanAttributes.TRACELOOP_ENTITY_VERSION, version);
}

if (shouldSendTraces()) {
try {
const input = inputParameters ?? args;
Expand Down
6 changes: 5 additions & 1 deletion packages/traceloop-sdk/test/decorators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe("Test SDK Decorators", () => {

it("should create spans for workflows using decoration syntax", async () => {
class TestOpenAI {
@traceloop.workflow({ name: "sample_chat" })
@traceloop.workflow({ name: "sample_chat", version: 2 })
async chat(things: Map<string, string>) {
const generations: Map<string, string> = new Map();
for await (const [key, value] of things) {
Expand Down Expand Up @@ -195,6 +195,10 @@ describe("Test SDK Decorators", () => {
workflowSpan.attributes[`${SpanAttributes.TRACELOOP_ENTITY_NAME}`],
"sample_chat",
);
assert.strictEqual(
workflowSpan.attributes[`${SpanAttributes.TRACELOOP_ENTITY_VERSION}`],
2,
);
assert.strictEqual(
workflowSpan.attributes[`${SpanAttributes.TRACELOOP_ENTITY_INPUT}`],
JSON.stringify({
Expand Down

0 comments on commit eb6211f

Please sign in to comment.