22
33import datadog .communication .ddagent .SharedCommunicationObjects ;
44import datadog .trace .api .Config ;
5+ import datadog .trace .api .WellKnownTags ;
56import datadog .trace .api .llmobs .LLMObs ;
67import datadog .trace .api .llmobs .LLMObsSpan ;
78import datadog .trace .api .llmobs .LLMObsTags ;
@@ -31,12 +32,9 @@ public static void start(Instrumentation inst, SharedCommunicationObjects sco) {
3132
3233 sco .createRemaining (config );
3334
34- LLMObsInternal .setLLMObsSpanFactory (
35- new LLMObsManualSpanFactory (config .getLlmObsMlApp (), config .getServiceName ()));
36-
3735 String mlApp = config .getLlmObsMlApp ();
38- LLMObsInternal . setLLMObsSpanFactory (
39- new LLMObsManualSpanFactory (mlApp , config . getServiceName () ));
36+ WellKnownTags wellKnownTags = config . getWellKnownTags ();
37+ LLMObsInternal . setLLMObsSpanFactory ( new LLMObsManualSpanFactory (mlApp , wellKnownTags ));
4038
4139 LLMObsInternal .setLLMObsEvalProcessor (new LLMObsCustomEvalProcessor (mlApp , sco , config ));
4240 }
@@ -129,12 +127,14 @@ public void SubmitEvaluation(
129127
130128 private static class LLMObsManualSpanFactory implements LLMObs .LLMObsSpanFactory {
131129
132- private final String serviceName ;
133130 private final String defaultMLApp ;
131+ private final String serviceName ;
132+ private final WellKnownTags wellKnownTags ;
134133
135- public LLMObsManualSpanFactory (String defaultMLApp , String serviceName ) {
134+ public LLMObsManualSpanFactory (String defaultMLApp , WellKnownTags wellKnownTags ) {
136135 this .defaultMLApp = defaultMLApp ;
137- this .serviceName = serviceName ;
136+ this .serviceName = wellKnownTags .getService ().toString ();
137+ this .wellKnownTags = wellKnownTags ;
138138 }
139139
140140 @ Override
@@ -147,7 +147,7 @@ public LLMObsSpan startLLMSpan(
147147
148148 DDLLMObsSpan span =
149149 new DDLLMObsSpan (
150- Tags .LLMOBS_LLM_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName );
150+ Tags .LLMOBS_LLM_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName , wellKnownTags );
151151
152152 if (modelName == null || modelName .isEmpty ()) {
153153 modelName = CUSTOM_MODEL_VAL ;
@@ -165,28 +165,28 @@ public LLMObsSpan startLLMSpan(
165165 public LLMObsSpan startAgentSpan (
166166 String spanName , @ Nullable String mlApp , @ Nullable String sessionId ) {
167167 return new DDLLMObsSpan (
168- Tags .LLMOBS_AGENT_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName );
168+ Tags .LLMOBS_AGENT_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName , wellKnownTags );
169169 }
170170
171171 @ Override
172172 public LLMObsSpan startToolSpan (
173173 String spanName , @ Nullable String mlApp , @ Nullable String sessionId ) {
174174 return new DDLLMObsSpan (
175- Tags .LLMOBS_TOOL_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName );
175+ Tags .LLMOBS_TOOL_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName , wellKnownTags );
176176 }
177177
178178 @ Override
179179 public LLMObsSpan startTaskSpan (
180180 String spanName , @ Nullable String mlApp , @ Nullable String sessionId ) {
181181 return new DDLLMObsSpan (
182- Tags .LLMOBS_TASK_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName );
182+ Tags .LLMOBS_TASK_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName , wellKnownTags );
183183 }
184184
185185 @ Override
186186 public LLMObsSpan startWorkflowSpan (
187187 String spanName , @ Nullable String mlApp , @ Nullable String sessionId ) {
188188 return new DDLLMObsSpan (
189- Tags .LLMOBS_WORKFLOW_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName );
189+ Tags .LLMOBS_WORKFLOW_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName , wellKnownTags );
190190 }
191191
192192 @ Override
@@ -201,7 +201,7 @@ public LLMObsSpan startEmbeddingSpan(
201201 }
202202 DDLLMObsSpan embeddingSpan =
203203 new DDLLMObsSpan (
204- Tags .LLMOBS_EMBEDDING_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName );
204+ Tags .LLMOBS_EMBEDDING_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName , wellKnownTags );
205205 embeddingSpan .setTag (LLMObsTags .MODEL_PROVIDER , modelProvider );
206206 embeddingSpan .setTag (LLMObsTags .MODEL_NAME , modelName );
207207 return embeddingSpan ;
@@ -210,7 +210,7 @@ public LLMObsSpan startEmbeddingSpan(
210210 public LLMObsSpan startRetrievalSpan (
211211 String spanName , @ Nullable String mlApp , @ Nullable String sessionId ) {
212212 return new DDLLMObsSpan (
213- Tags .LLMOBS_RETRIEVAL_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName );
213+ Tags .LLMOBS_RETRIEVAL_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName , wellKnownTags );
214214 }
215215
216216 private String getMLApp (String mlApp ) {
0 commit comments