Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk): versions on workflows & tasks #353

Merged
merged 1 commit into from
Jul 4, 2024
Merged
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
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
Loading