-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy pathLLMObsState.java
More file actions
37 lines (29 loc) · 1.02 KB
/
LLMObsState.java
File metadata and controls
37 lines (29 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package datadog.trace.llmobs.domain;
import datadog.context.Context;
import datadog.context.ContextKey;
import datadog.context.ContextScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext;
public class LLMObsState {
public static final String ROOT_SPAN_ID = "undefined";
private static final ContextKey<LLMObsState> CONTEXT_KEY = ContextKey.named("llmobs_span");
private AgentSpanContext parentSpanID;
public static ContextScope attach() {
return Context.current().with(CONTEXT_KEY, new LLMObsState()).attach();
}
private static LLMObsState fromContext() {
return Context.current().get(CONTEXT_KEY);
}
public static AgentSpanContext getLLMObsParentContext() {
LLMObsState state = fromContext();
if (state != null) {
return state.parentSpanID;
}
return null;
}
public static void setLLMObsParentContext(AgentSpanContext llmObsParentContext) {
LLMObsState state = fromContext();
if (state != null) {
state.parentSpanID = llmObsParentContext;
}
}
}