8000 working writer · DataDog/dd-trace-java@738eb77 · GitHub
[go: up one dir, main page]

Skip to content

Commit 738eb77

Browse files
committed
working writer
1 parent 273e2ac commit 738eb77

File tree

14 files changed

+376
-14
lines changed

14 files changed

+376
-14
lines changed

communication/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dependencies {
44
implementation libs.slf4j
55

66
api project(':remote-config:remote-config-api')
7+
implementation project(':components:json')
78
implementation project(':remote-config:remote-config-core')
89
implementation project(':internal-api')
910
implementation project(':utils:container-utils')

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/Agent.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
3838
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.TracerAPI;
3939
import datadog.trace.bootstrap.instrumentation.api.ProfilingContextIntegration;
40+
import datadog.trace.bootstrap.instrumentation.api.WriterConstants;
4041
import datadog.trace.bootstrap.instrumentation.jfr.InstrumentationBasedProfiling;
4142
import datadog.trace.util.AgentTaskScheduler;
4243
import datadog.trace.util.AgentThreadFactory.AgentThread;
@@ -111,7 +112,8 @@ private enum AgentFeature {
111112
DATA_JOBS(propertyNameToSystemPropertyName(GeneralConfig.DATA_JOBS_ENABLED), false),
112113
AGENTLESS_LOG_SUBMISSION(
113114
propertyNameToSystemPropertyName(GeneralConfig.AGENTLESS_LOG_SUBMISSION_ENABLED), false),
114-
LLMOBS(propertyNameToSystemPropertyName(LlmObsConfig.LLMOBS_ENABLED), false);
115+
LLMOBS(propertyNameToSystemPropertyName(LlmObsConfig.LLMOBS_ENABLED), false),
116+
LLMOBS_AGENTLESS(propertyNameToSystemPropertyName(LlmObsConfig.LLMOBS_AGENTLESS_ENABLED), false);
115117

116118
private final String systemProp;
117119
private final boolean enabledByDefault;
@@ -153,6 +155,7 @@ public boolean isEnabledByDefault() {
153155
private static boolean cwsEnabled = false;
154156
private static boolean ciVisibilityEnabled = false;
155157
private static boolean llmObsEnabled = false;
158+
private static boolean llmObsAgentlessEnabled = false;
156159
private static boolean usmEnabled = false;
157160
private static boolean telemetryEnabled = true;
158161
private static boolean debuggerEnabled = false;
@@ -273,6 +276,15 @@ public static void start(
273276
agentlessLogSubmissionEnabled = isFeatureEnabled(AgentFeature.AGENTLESS_LOG_SUBMISSION);
274277
llmObsEnabled = isFeatureEnabled(AgentFeature.LLMOBS);
275278

279+
if (llmObsEnabled) {
280+
// for llm obs spans, use agent proxy by default, apm spans will use agent writer
281+
setSystemPropertyDefault(propertyNameToSystemPropertyName(TracerConfig.WRITER_TYPE), WriterConstants.MULTI_WRITER_TYPE + ":" + WriterConstants.DD_INTAKE_WRITER_TYPE + "," + WriterConstants.DD_AGENT_WRITER_TYPE);
282+
if (llmObsAgentlessEnabled) {
283+
// use API writer only
284+
setSystemPropertyDefault(propertyNameToSystemPropertyName(TracerConfig.WRITER_TYPE), WriterConstants.DD_INTAKE_WRITER_TYPE);
285+
}
286+
}
287+
276288
if (profilingEnabled) {
277289
if (!isOracleJDK8()) {
278290
// Profiling agent startup code is written in a way to allow `startProfilingAgent` be called

dd-trace-api/src/main/java/datadog/trace/api/llmobs/LLMObsConstants.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

dd-trace-core/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ dependencies {
6868
implementation project(':components:json')
6969
implementation project(':utils:container-utils')
7070
implementation project(':utils:socket-utils')
71+
72+
implementation group: 'org.msgpack', name: 'msgpack-core', version: '0.8.10'
73+
implementation group: 'org.msgpack', name: 'jackson-dataformat-msgpack', version: '0.8.10'
74+
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.10.0'
75+
7176
// for span exception debugging
7277
compileOnly project(':dd-java-agent:agent-debugger:debugger-bootstrap')
7378

dd-trace-core/src/main/java/datadog/trace/common/writer/DDAgentWriter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public DDAgentWriter build() {
151151
}
152152

153153
final DDAgentMapperDiscovery mapperDiscovery = new DDAgentMapperDiscovery(featureDiscovery);
154+
154155
final PayloadDispatcher dispatcher =
155156
new PayloadDispatcherImpl(mapperDiscovery, agentApi, healthMetrics, monitoring);
156157
final TraceProcessingWorker traceProcessingWorker =

dd-trace-core/src/main/java/datadog/trace/common/writer/WriterFactory.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static Writer createWriter(
8282

8383
// The AgentWriter doesn't support the CI Visibility protocol. If CI Visibility is
8484
// enabled, check if we can use the IntakeWriter instead.
85-
if (DD_AGENT_WRITER_TYPE.equals(configuredType) && config.isCiVisibilityEnabled()) {
85+
if (DD_AGENT_WRITER_TYPE.equals(configuredType) && (config.isCiVisibilityEnabled())) {
8686
if (featuresDiscovery.supportsEvpProxy() || config.isCiVisibilityAgentlessEnabled()) {
8787
configuredType = DD_INTAKE_WRITER_TYPE;
8888
} else {
@@ -116,6 +116,10 @@ public static Writer createWriter(
116116
builder.addTrack(TrackType.CITESTCOV, coverageApi);
117117
}
118118

119+
final RemoteApi llmobsApi =
120+
createDDIntakeRemoteApi(config, commObjects, featuresDiscovery, TrackType.LLMOBS);
121+
builder.addTrack(TrackType.LLMOBS, llmobsApi);
122+
119123
remoteWriter = builder.build();
120124

121125
} else { // configuredType == DDAgentWriter
@@ -171,26 +175,37 @@ private static RemoteApi createDDIntakeRemoteApi(
171175
SharedCommunicationObjects commObjects,
172176
DDAgentFeaturesDiscovery featuresDiscovery,
173177
TrackType trackType) {
174-
if (featuresDiscovery.supportsEvpProxy() && !config.isCiVisibilityAgentlessEnabled()) {
178+
boolean evpProxySupported = featuresDiscovery.supportsEvpProxy();
179+
boolean useProxyApi = (evpProxySupported && TrackType.LLMOBS == trackType && !config.isLlmObsAgentlessEnabled())
180+
|| (evpProxySupported && (TrackType.CITESTCOV == trackType || TrackType.CITESTCYCLE == trackType) && !config.isCiVisibilityAgentlessEnabled());
181+
182+
if (useProxyApi) {
175183
return DDEvpProxyApi.builder()
176184
.httpClient(commObjects.okHttpClient)
177185
.agentUrl(commObjects.agentUrl)
178186
.evpProxyEndpoint(featuresDiscovery.getEvpProxyEndpoint())
179187
.trackType(trackType)
180188
.compressionEnabled(featuresDiscovery.supportsContentEncodingHeadersWithEvpProxy())
181189
.build();
182-
183190
} else {
184191
HttpUrl hostUrl = null;
192+
String llmObsAgentlessUrl = config.getLlMObsAgentlessUrl();
193+
185194
if (config.getCiVisibilityAgentlessUrl() != null) {
186195
hostUrl = HttpUrl.get(config.getCiVisibilityAgentlessUrl());
187196
log.info("Using host URL '{}' to report CI Visibility traces in Agentless mode.", hostUrl);
197+
} else if (config.isLlmObsEnabled()
198+
&& config.isLlmObsAgentlessEnabled()
199+
&& llmObsAgentlessUrl != null
200+
&& !llmObsAgentlessUrl.isEmpty()) {
201+
hostUrl = HttpUrl.get(llmObsAgentlessUrl);
202+
log.info("Using host URL '{}' to report LLM Obs traces in Agentless mode.", hostUrl);
188203
}
189204
return DDIntakeApi.builder()
190-
.hostUrl(hostUrl)
191-
.apiKey(config.getApiKey())
192-
.trackType(trackType)
193-
.build();
205+
.hostUrl(hostUrl)
206+
.apiKey(config.getApiKey())
207+
.trackType(trackType)
208+
.build();
194209
}
195210
}
196211

dd-trace-core/src/main/java/datadog/trace/common/writer/ddagent/DDAgentApi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public void addResponseListener(final RemoteResponseListener listener) {
9090
public Response se 6377 ndSerializedTraces(final Payload payload) {
9191
final int sizeInBytes = payload.sizeInBytes();
9292
String tracesEndpoint = featuresDiscovery.getTraceEndpoint();
93+
9394
if (null == tracesEndpoint) {
9495
featuresDiscovery.discoverIfOutdated();
9596
tracesEndpoint = featuresDiscovery.getTraceEndpoint();

dd-trace-core/src/main/java/datadog/trace/common/writer/ddintake/DDIntakeApi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public Response sendSerializedTraces(Payload payload) {
131131
.post(payload.toRequest())
132132
.tag(OkHttpUtils.CustomListener.class, telemetryListener)
133133
.build();
134+
134135
totalTraces += payload.traceCount();
135136
receivedTraces += payload.traceCount();
136137

dd-trace-core/src/main/java/datadog/trace/common/writer/ddintake/DDIntakeMapperDiscovery.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import datadog.trace.civisibility.writer.ddintake.CiTestCycleMapperV1;
77
import datadog.trace.common.writer.RemoteMapper;
88
import datadog.trace.common.writer.RemoteMapperDiscovery;
9+
import datadog.trace.llmobs.writer.ddintake.LLMObsSpanMapper;
910

1011
/**
1112
* Mapper discovery logic when a DDIntake is used. The mapper is discovered based on a backend
@@ -40,6 +41,8 @@ public void discover() {
4041
mapper = new CiTestCycleMapperV1(wellKnownTags, compressionEnabled);
4142
} else if (TrackType.CITESTCOV.equals(trackType)) {
4243
mapper = new CiTestCovMapperV2(compressionEnabled);
44+
} else if (TrackType.LLMOBS.equals(trackType)) {
45+
mapper = new LLMObsSpanMapper();
4346
} else {
4447
mapper = RemoteMapper.NO_OP;
4548
}

0 commit comments

Comments
 (0)
0