Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package datadog.trace.llmobs.domain;

import datadog.context.ContextScope;
import datadog.trace.api.Config;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTraceId;
import datadog.trace.api.WellKnownTags;
Expand Down Expand Up @@ -72,6 +73,11 @@ public DDLLMObsSpan(

span = spanBuilder.start();

// set global dd_tags as base layer so UST and span-level tags can override them
for (Map.Entry<String, String> entry : Config.get().getGlobalTags().entrySet()) {
span.setTag(LLMOBS_TAG_PREFIX + entry.getKey(), entry.getValue());
}

// set UST (unified service tags, env, service, version)
span.setTag(ENV, wellKnownTags.getEnv());
span.setTag(SERVICE, wellKnownTags.getService());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,17 @@ class DDLLMObsSpanTest extends DDSpecification{
null | "has_session_id:0"
}

def "global dd_tags are included in LLMObs span tags"() {
setup:
injectSysConfig("trace.global.tags", "team:backend,owner:ml-platform")
def test = llmObsSpan(Tags.LLMOBS_WORKFLOW_SPAN_KIND, "test-span")

expect:
def innerSpan = (AgentSpan) test.span
innerSpan.getTag(LLMOBS_TAG_PREFIX + "team") == "backend"
innerSpan.getTag(LLMOBS_TAG_PREFIX + "owner") == "ml-platform"
}

private LLMObsSpan llmObsSpan(String kind, name) {
llmObsSpan(kind, name, null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
import datadog.trace.bootstrap.instrumentation.decorator.ClientDecorator;
import java.util.List;
import java.util.Map;

public class OpenAiDecorator extends ClientDecorator {
public static final OpenAiDecorator DECORATE = new OpenAiDecorator();
Expand Down Expand Up @@ -91,6 +92,11 @@ protected CharSequence component() {
@Override
public AgentSpan afterStart(AgentSpan span) {
if (llmObsEnabled) {
// set global dd_tags as base layer so UST and span-level tags can override them
for (Map.Entry<String, String> entry : Config.get().getGlobalTags().entrySet()) {
span.setTag(CommonTags.TAG_PREFIX + entry.getKey(), entry.getValue());
}

// set UST (unified service tags, env, service, version)
span.setTag(CommonTags.ENV, wellKnownTags.getEnv());
span.setTag(CommonTags.SERVICE, wellKnownTags.getService());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace

/**
* Verifies that global tags (dd.trace.global.tags / DD_TAGS) are propagated to LLMObs span tags in the OpenAI instrumentation.
*/
class GlobalTagsTest extends OpenAiTest {

@Override
void configurePreAgent() {
super.configurePreAgent()
injectSysConfig("trace.global.tags", "team:backend,owner:ml-platform")
}

def "global dd_tags are included in OpenAI LLMObs span tags"() {
when:
runUnderTrace("parent") {
openAiClient.chat().completions().create(chatCompletionCreateParams(false))
}
TEST_WRITER.waitForTraces(1)
def openAiSpan = TEST_WRITER.flatten().find { it.operationName.toString() == "openai.request" }

then:
openAiSpan.getTag("_ml_obs_tag.team") == "backend"
openAiSpan.getTag("_ml_obs_tag.owner") == "ml-platform"
}
}
Loading