-
Notifications
You must be signed in to change notification settings - Fork 334
Fix OtelLogRecordProcessor schedule #11315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gh-worker-dd-mergequeue-cf854d
merged 2 commits into
master
from
mcculls/fix-otlp-log-schedule
May 8, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
dd-trace-core/src/main/java/datadog/trace/core/otlp/logs/NoopOtlpLogsCollector.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,13 @@ | ||
| package datadog.trace.core.otlp.logs; | ||
|
|
||
| import static datadog.trace.util.AgentThreadFactory.AgentThread.OTLP_LOGS_EXPORTER; | ||
| import static datadog.trace.util.AgentThreadFactory.newAgentThread; | ||
|
|
||
| import datadog.trace.api.Config; | ||
| import datadog.trace.core.otlp.common.OtlpGrpcSender; | ||
| import datadog.trace.core.otlp.common.OtlpHttpSender; | ||
| import datadog.trace.core.otlp.common.OtlpPayload; | ||
| import datadog.trace.core.otlp.common.OtlpSender; | ||
| import datadog.trace.util.AgentTaskScheduler; | ||
| import java.util.concurrent.ThreadLocalRandom; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
|
|
@@ -19,17 +17,14 @@ public final class OtlpLogsService { | |
|
|
||
| public static final OtlpLogsService INSTANCE = new OtlpLogsService(Config.get()); | ||
|
|
||
| private final AgentTaskScheduler scheduler; | ||
| private final int intervalMillis; | ||
| private final OtlpLogsCollector collector; | ||
| private final OtlpSender sender; | ||
|
|
||
| private final int intervalMillis; | ||
|
|
||
| private AgentTaskScheduler.Scheduled<?> scheduledTask = null; | ||
| private volatile Thread exporterThread; | ||
|
|
||
| private OtlpLogsService(Config config) { | ||
| this.scheduler = new AgentTaskScheduler(OTLP_LOGS_EXPORTER); | ||
|
|
||
| intervalMillis = config.getLogsOtelInterval(); | ||
| switch (config.getOtlpLogsProtocol()) { | ||
| case GRPC: | ||
| this.collector = OtlpLogsProtoCollector.INSTANCE; | ||
|
|
@@ -53,51 +48,52 @@ private OtlpLogsService(Config config) { | |
| break; | ||
| default: | ||
| LOGGER.debug("Unsupported OTLP logs protocol: {}", config.getOtlpLogsProtocol()); | ||
| this.collector = NoopOtlpLogsCollector.INSTANCE; | ||
| this.collector = null; | ||
| this.sender = null; | ||
| } | ||
|
|
||
| this.intervalMillis = config.getLogsOtelInterval(); | ||
| } | ||
|
|
||
| public void start() { | ||
| if (sender == null) { | ||
| return; | ||
| } | ||
|
|
||
| // add random jitter of up to 5 seconds to initial delay; avoids a fleet | ||
| // of apps starting at the same time from exporting OTLP logs in sync | ||
| long initialMillis = | ||
| intervalMillis | ||
| + Math.min( | ||
| (long) | ||
| (500d | ||
| * Math.log(ThreadLocalRandom.current().nextDouble()) | ||
| / Math.log(1 - 0.25)), | ||
| 5_000); | ||
|
|
||
| scheduledTask = | ||
| scheduler.scheduleAtFixedRate( | ||
| this::export, initialMillis, intervalMillis, TimeUnit.MILLISECONDS); | ||
| exporterThread = newAgentThread(OTLP_LOGS_EXPORTER, this::export); | ||
| exporterThread.start(); | ||
| } | ||
|
|
||
| public void flush() { | ||
| scheduler.execute(this::export); | ||
| Thread thread = exporterThread; | ||
| if (thread != null) { | ||
| thread.interrupt(); | ||
| } | ||
| } | ||
|
|
||
| public void shutdown() { | ||
| if (scheduledTask != null) { | ||
| scheduledTask.cancel(); | ||
| Thread thread = exporterThread; | ||
| if (thread != null) { | ||
| exporterThread = null; | ||
| thread.interrupt(); | ||
| try { | ||
| thread.join(1_000); | ||
| } catch (InterruptedException ignore) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm okay with foregoing reseting interrupt here, since we're mid shutdown. |
||
| } | ||
| } | ||
| if (sender != null) { | ||
| sender.shutdown(); | ||
| } | ||
| } | ||
|
|
||
| private void export() { | ||
| OtlpPayload payload = collector.collectLogs(); | ||
| if (payload != OtlpPayload.EMPTY) { | ||
| sender.send(payload); | ||
| while (Thread.currentThread() == exporterThread) { | ||
| try { | ||
| OtlpPayload payload = collector.waitForLogs(intervalMillis); | ||
| if (payload != OtlpPayload.EMPTY) { | ||
| sender.send(payload); | ||
| } | ||
| } catch (RuntimeException e) { | ||
| LOGGER.debug("Uncaught exception exporting logs", e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
11 changes: 0 additions & 11 deletions
11
dd-trace-core/src/main/java/datadog/trace/core/otlp/metrics/NoopOtlpMetricsCollector.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As general practice, we should reset the interrupt status after catching InterruptedException.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general yes - but only if we want to preserve and report the interrupted status to callers, which is not the case here.
In this situation we want to bail out of the method and return what we've batched so far (so it isn't dropped.) The caller then may decide to invoke
waitForLogsagain, and we don't want to have the interrupted status kept as thenpollwould immediately fail again.We could potentially let the
InterruptedExceptionbubble up, but that would lead to a loss of logs if we're interrupting because of shutdown, where we want to interrupt any blocking while waiting for enough logs for the batch but still have one last attempt to flush what we have.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a comment to make this particular situation clear for future devs