Skip to content

Commit 3e530bc

Browse files
authored
fix(sdk): propagate association properties within a workflow (#318)
1 parent 1314a24 commit 3e530bc

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sample-app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"cohere-ai": "^7.7.5",
4444
"langchain": "^0.1.7",
4545
"llamaindex": "^0.1.16",
46-
"openai": "^4.12.4",
46+
"openai": "^4.28.4",
4747
"chromadb": "^1.8.1"
4848
},
4949
"private": true,

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { Span, context } from "@opentelemetry/api";
2-
import { getTracer, WORKFLOW_NAME_KEY } from "./tracing";
2+
import {
3+
ASSOCATION_PROPERTIES_KEY,
4+
getTracer,
5+
WORKFLOW_NAME_KEY,
6+
} from "./tracing";
37
import {
48
CONTEXT_KEY_ALLOW_TRACE_CONTENT,
59
SpanAttributes,
610
TraceloopSpanKindValues,
711
} from "@traceloop/ai-semantic-conventions";
8-
import { withAssociationProperties } from "./association";
912
import { shouldSendTraces } from ".";
1013
import { Telemetry } from "../telemetry/telemetry";
1114

@@ -44,8 +47,14 @@ function withEntity<
4447
overrideTraceContent,
4548
);
4649
}
50+
if (associationProperties) {
51+
entityContext = entityContext.setValue(
52+
ASSOCATION_PROPERTIES_KEY,
53+
associationProperties,
54+
);
55+
}
4756

48-
return withAssociationProperties(associationProperties ?? {}, () =>
57+
return context.with(entityContext, () =>
4958
getTracer().startActiveSpan(
5059
`${name}.${type}`,
5160
{},

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe("Test SDK Decorators", () => {
7676
it("should create spans for workflows using withWorkflow syntax", async () => {
7777
const jokeSubject = "OpenTelemetry";
7878
const result = await traceloop.withWorkflow(
79-
{ name: "sample_chat" },
79+
{ name: "sample_chat", associationProperties: { userId: "123" } },
8080
async () => {
8181
const chatCompletion = await openai.chat.completions.create({
8282
messages: [
@@ -110,6 +110,12 @@ describe("Test SDK Decorators", () => {
110110
workflowSpan.attributes[`${SpanAttributes.TRACELOOP_ENTITY_NAME}`],
111111
"sample_chat",
112112
);
113+
assert.strictEqual(
114+
workflowSpan.attributes[
115+
`${SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.userId`
116+
],
117+
"123",
118+
);
113119
assert.strictEqual(
114120
workflowSpan.attributes[`${SpanAttributes.TRACELOOP_ENTITY_INPUT}`],
115121
JSON.stringify({ args: [], kwargs: { jokeSubject: "OpenTelemetry" } }),
@@ -119,6 +125,12 @@ describe("Test SDK Decorators", () => {
119125
JSON.stringify(result),
120126
);
121127
assert.ok(chatSpan);
128+
assert.strictEqual(
129+
chatSpan.attributes[
130+
`${SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.userId`
131+
],
132+
"123",
133+
);
122134
assert.strictEqual(
123135
chatSpan.attributes[`${SpanAttributes.TRACELOOP_WORKFLOW_NAME}`],
124136
"sample_chat",

0 commit comments

Comments
 (0)