feat: Add OpenTelemetry tracing spans for batch job operations#3445
feat: Add OpenTelemetry tracing spans for batch job operations#3445
Conversation
- Added OpenTelemetry instrumentation annotations dependency - Added @WithSpan annotations to key batch job methods: - OldBatchJobCleaner: cleanup operations and database updates - BatchJobActivityFinalizer: activity revision merging - ChunkProcessingUtil: chunk processing logic - BatchJobActionService: chunk execution and database locking - Added span attributes to handleItem for better trace filtering: - batch.job.id - batch.chunk.execution.id - project.id This improves observability by creating properly named spans for all batch job operations, making it easier to trace DELETE and UPDATE operations on activity tables. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe PR adds OpenTelemetry instrumentation annotations and tracing spans to batch job processing services. Build configuration is updated with the opentelemetry-instrumentation-annotations dependency and version property. The Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Important Action Needed: IP Allowlist UpdateIf your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:
Failure to add the new IP will result in interrupted reviews. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
backend/data/src/main/kotlin/io/tolgee/batch/BatchJobActionService.kt (1)
254-271:⚠️ Potential issue | 🟡 MinorRemove
@WithSpanannotation from private method or refactor to separate bean.Spring AOP proxies cannot intercept private methods (CGLIB cannot override private methods), and since
getExecutionIfCanAcquireLockInDbis invoked via self-invocation fromgetPendingUnlockedExecutionItem, the@WithSpanannotation will not create a span.Either remove the annotation (the parent span from
handleItemalready covers this operation), make the method public and call it through a separate Spring-managed bean, or use manual span creation similar tohandleItemif dedicated tracing for this lock acquisition is needed.
🤖 Fix all issues with AI agents
In `@backend/data/build.gradle`:
- Line 185: Update the OpenTelemetry instrumentation annotations dependency
version from 2.10.0 to 2.24.0 by changing the implementation declaration that
references
"io.opentelemetry.instrumentation:opentelemetry-instrumentation-annotations:2.10.0"
to use 2.24.0; optionally extract this coordinate into the project’s version
catalog (so other modules can reference a managed version) and replace the
literal with the catalog reference to keep dependency versions consistent.
In
`@backend/data/src/main/kotlin/io/tolgee/batch/BatchJobProjectLockingManager.kt`:
- Line 3: Remove the unused import
io.opentelemetry.instrumentation.annotations.WithSpan from the
BatchJobProjectLockingManager file; locate the import block at the top of the
file (around class BatchJobProjectLockingManager) and delete that specific
import line so the file no longer references WithSpan.
🧹 Nitpick comments (1)
backend/data/src/main/kotlin/io/tolgee/batch/cleaning/OldBatchJobCleaner.kt (1)
102-116: Consider span attribute for batch size context.The
deleteJobBatchspan would benefit from attributes indicating how many jobs/chunks are being processed in this batch, similar to howBatchJobActionService.handleItemadds context attributes.💡 Optional enhancement for span attributes
+ import io.opentelemetry.api.trace.Span + `@WithSpan` private fun deleteJobBatch( statuses: List<String>, cutoffDate: Date, ): Pair<Int, Int> { val jobIds = findJobIdsToDelete(statuses, cutoffDate) if (jobIds.isEmpty()) return Pair(0, 0) + Span.current().setAttribute("batch.job.count", jobIds.size.toLong()) val executionIds = findExecutionIds(jobIds) + Span.current().setAttribute("batch.execution.count", executionIds.size.toLong())
backend/data/src/main/kotlin/io/tolgee/batch/BatchJobProjectLockingManager.kt
Outdated
Show resolved
Hide resolved
backend/data/src/main/kotlin/io/tolgee/batch/BatchJobActionService.kt
Outdated
Show resolved
Hide resolved
backend/data/src/main/kotlin/io/tolgee/batch/BatchJobActionService.kt
Outdated
Show resolved
Hide resolved
backend/data/src/main/kotlin/io/tolgee/batch/cleaning/OldBatchJobCleaner.kt
Show resolved
Hide resolved
- Added opentelemetryInstrumentationVersion to gradle.properties - Added library definition to settings.gradle version catalog - Updated data/build.gradle to use libs.opentelemetryInstrumentationAnnotations This centralizes version management and follows the project's dependency management strategy.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@gradle.properties`:
- Around line 12-14: The opentelemetryInstrumentationVersion constant is out of
sync with opentelemetryJavaagentVersion; update
opentelemetryInstrumentationVersion to the same release string as
opentelemetryJavaagentVersion (set opentelemetryInstrumentationVersion to
2.24.0) so both versions align (look for the opentelemetryJavaagentVersion and
opentelemetryInstrumentationVersion entries in gradle.properties).
In `@settings.gradle`:
- Line 82: Update the OpenTelemetry annotation version so it matches the
javaagent: change the opentelemetryInstrumentationVersion value in
gradle.properties to 2.24.0 so the dependency declared with
library('opentelemetryInstrumentationAnnotations',
'io.opentelemetry.instrumentation',
'opentelemetry-instrumentation-annotations').version(opentelemetryInstrumentationVersion)
uses the same 2.x version as the opentelemetry-javaagent.
- Updated OpenTelemetry version from 2.10.0 to 2.24.0 - Simplified handleItem span creation using @WithSpan + Span.current() - Removed unnecessary baggage/scope management complexity - Added span attributes for batch.job.id, batch.chunk.execution.id, project.id - Removed unused WithSpan import from BatchJobProjectLockingManager Changes address reviewer feedback: - gabrielshanahan: Simplified span creation pattern - CodeRabbit: Updated to latest version, removed unused import - Kept span attributes instead of baggage for simpler, more focused approach Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
gabrielshanahan
left a comment
There was a problem hiding this comment.
Superseded by #3450
Summary
@WithSpanannotations to key methods handling database operations on activity tableshandleItemfor better trace filteringChanges
Dependencies
io.opentelemetry.instrumentation:opentelemetry-instrumentation-annotations:2.10.0Instrumented Components
OldBatchJobCleaner - Batch job cleanup operations:
BatchJobActivityFinalizer - Activity revision merging:
ChunkProcessingUtil - Chunk processing:
BatchJobActionService - Chunk execution:
batch.job.id,batch.chunk.execution.id,project.idBenefits
Testing
🤖 Generated with Claude Code
Summary by CodeRabbit