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,12 @@ 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 ,
151+ spanName ,
152+ getMLApp (mlApp ),
153+ sessionId ,
154+ serviceName ,
155+ wellKnownTags );
151156
152157 if (modelName == null || modelName .isEmpty ()) {
153158 modelName = CUSTOM_MODEL_VAL ;
@@ -165,28 +170,48 @@ public LLMObsSpan startLLMSpan(
165170 public LLMObsSpan startAgentSpan (
166171 String spanName , @ Nullable String mlApp , @ Nullable String sessionId ) {
167172 return new DDLLMObsSpan (
168- Tags .LLMOBS_AGENT_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName );
173+ Tags .LLMOBS_AGENT_SPAN_KIND ,
174+ spanName ,
175+ getMLApp (mlApp ),
176+ sessionId ,
177+ serviceName ,
178+ wellKnownTags );
169179 }
170180
171181 @ Override
172182 public LLMObsSpan startToolSpan (
173183 String spanName , @ Nullable String mlApp , @ Nullable String sessionId ) {
174184 return new DDLLMObsSpan (
175- Tags .LLMOBS_TOOL_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName );
185+ Tags .LLMOBS_TOOL_SPAN_KIND ,
186+ spanName ,
187+ getMLApp (mlApp ),
188+ sessionId ,
189+ serviceName ,
190+ wellKnownTags );
176191 }
177192
178193 @ Override
179194 public LLMObsSpan startTaskSpan (
180195 String spanName , @ Nullable String mlApp , @ Nullable String sessionId ) {
181196 return new DDLLMObsSpan (
182- Tags .LLMOBS_TASK_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName );
197+ Tags .LLMOBS_TASK_SPAN_KIND ,
198+ spanName ,
199+ getMLApp (mlApp ),
200+ sessionId ,
201+ serviceName ,
202+ wellKnownTags );
183203 }
184204
185205 @ Override
186206 public LLMObsSpan startWorkflowSpan (
187207 String spanName , @ Nullable String mlApp , @ Nullable String sessionId ) {
188208 return new DDLLMObsSpan (
189- Tags .LLMOBS_WORKFLOW_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName );
209+ Tags .LLMOBS_WORKFLOW_SPAN_KIND ,
210+ spanName ,
211+ getMLApp (mlApp ),
212+ sessionId ,
213+ serviceName ,
214+ wellKnownTags );
190215 }
191216
192217 @ Override
@@ -201,7 +226,12 @@ public LLMObsSpan startEmbeddingSpan(
201226 }
202227 DDLLMObsSpan embeddingSpan =
203228 new DDLLMObsSpan (
204- Tags .LLMOBS_EMBEDDING_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName );
229+ Tags .LLMOBS_EMBEDDING_SPAN_KIND ,
230+ spanName ,
231+ getMLApp (mlApp ),
232+ sessionId ,
233+ serviceName ,
234+ wellKnownTags );
205235 embeddingSpan .setTag (LLMObsTags .MODEL_PROVIDER , modelProvider );
206236 embeddingSpan .setTag (LLMObsTags .MODEL_NAME , modelName );
207237 return embeddingSpan ;
@@ -210,7 +240,12 @@ public LLMObsSpan startEmbeddingSpan(
210240 public LLMObsSpan startRetrievalSpan (
211241 String spanName , @ Nullable String mlApp , @ Nullable String sessionId ) {
212242 return new DDLLMObsSpan (
213- Tags .LLMOBS_RETRIEVAL_SPAN_KIND , spanName , getMLApp (mlApp ), sessionId , serviceName );
243+ Tags .LLMOBS_RETRIEVAL_SPAN_KIND ,
244+ spanName ,
245+ getMLApp (mlApp ),
246+ sessionId ,
247+ serviceName ,
248+ wellKnownTags );
214249 }
215250
216251 private String getMLApp (String mlApp ) {
0 commit comments