Cleanup ContextStore API - #12352
Conversation
This comment has been minimized.
This comment has been minimized.
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
* putIfAbsent(value) to getOrPut * putIfAbsent(factory) to getOrCreate and default this to delegate to getOrCompute * computeIfAbsent(function) to getOrCompute
Kafka / producer-benchmarkParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics. See unchanged results
|
… clear it uses strong references
…tore, or allow for different max sizes
…me WeakMapContextStore to WeakMapPerStore
87d9e53 to
a4a1653
Compare
Kafka / consumer-benchmarkParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics. See unchanged results
|
|
@DataDog review |
There was a problem hiding this comment.
Pull request overview
Refactors the ContextStore/InstanceStore APIs to clearer “get-or-*” semantics, updates agent instrumentations and tests to the renamed methods, and adjusts the field-injection weak-map fallback plumbing.
Changes:
- Renames
ContextStoremethods (putIfAbsent/computeIfAbsent) togetOrPut/getOrCreate/getOrComputeand clarifies nullability/JavaDoc. - Updates a broad set of instrumentations and tests to the new
ContextStore/InstanceStoreAPI. - Reworks field-injection weak-map redirection to use
WeakMapPerStorehelpers and replaces CI Visibility’sConcurrentHashMapContextStorewithStrongMapContextStore.
Reviewed changes
Copilot reviewed 58 out of 58 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal-api/src/main/java/datadog/trace/bootstrap/ContextStore.java | Renames ContextStore API to getOr* methods; adds @Nullable on nullable operations. |
| internal-api/build.gradle.kts | Excludes ContextStore from coverage list. |
| dd-java-agent/instrumentation/websocket/jetty-websocket/jetty-websocket-10.0/src/main/java11/datadog/trace/instrumentation/websocket/jetty10/MethodHandleWrappers.java | Updates websocket session store usage to getOrPut. |
| dd-java-agent/instrumentation/websocket/javax-websocket-1.0/src/main/java/datadog/trace/instrumentation/websocket/jsr256/EndpointInstrumentation.java | Updates websocket session context storage to getOrPut. |
| dd-java-agent/instrumentation/undertow/undertow-common/src/main/java/datadog/trace/instrumentation/undertow/UndertowDecorator.java | Updates attachment store initialization to getOrCreate. |
| dd-java-agent/instrumentation/tomcat/tomcat-5.5/src/main/java/datadog/trace/instrumentation/tomcat/WsHandshakeRequestInstrumentation.java | Updates handshake span storage to getOrPut. |
| dd-java-agent/instrumentation/tibco-businessworks/tibco-businessworks-5.14/src/main/java/datadog/trace/instrumentation/tibcobw5/JobInstrumentation.java | Updates per-process map initialization to getOrCreate. |
| dd-java-agent/instrumentation/scalatest-3.0.8/src/main/java/datadog/trace/instrumentation/scalatest/ScalatestSkipInstrumentation.java | Updates filter context association to getOrPut. |
| dd-java-agent/instrumentation/resilience4j/resilience4j-reactor-2.0/src/main/java/datadog/trace/instrumentation/resilience4j/ReactorHelper.java | Updates publisher handoff storage to getOrPut. |
| dd-java-agent/instrumentation/reactor-core-3.1/src/main/java/datadog/trace/instrumentation/reactor/core/ReactorContextBridge.java | Updates subscriber context transfer to getOrPut. |
| dd-java-agent/instrumentation/reactive-streams-1.0/src/test/java/datadog/trace/instrumentation/reactivestreams/ReactiveStreamsContextPropagationTest.java | Updates test ContextStore implementation to new API names. |
| dd-java-agent/instrumentation/reactive-streams-1.0/src/main/java/datadog/trace/instrumentation/reactivestreams/ReactiveStreamsContextPropagation.java | Updates subscriber context capture to getOrPut. |
| dd-java-agent/instrumentation/netty/netty-3.8/src/main/java/datadog/trace/instrumentation/netty38/server/MaybeBlockResponseHandler.java | Updates channel context initialization to getOrCreate. |
| dd-java-agent/instrumentation/netty/netty-3.8/src/main/java/datadog/trace/instrumentation/netty38/server/HttpServerResponseTracingHandler.java | Updates channel context initialization to getOrCreate. |
| dd-java-agent/instrumentation/netty/netty-3.8/src/main/java/datadog/trace/instrumentation/netty38/server/HttpServerRequestTracingHandler.java | Updates channel context initialization to getOrCreate. |
| dd-java-agent/instrumentation/netty/netty-3.8/src/main/java/datadog/trace/instrumentation/netty38/NettyChannelInstrumentation.java | Updates channel context initialization to getOrCreate. |
| dd-java-agent/instrumentation/netty/netty-3.8/src/main/java/datadog/trace/instrumentation/netty38/client/HttpClientResponseTracingHandler.java | Updates channel context initialization to getOrCreate. |
| dd-java-agent/instrumentation/netty/netty-3.8/src/main/java/datadog/trace/instrumentation/netty38/client/HttpClientRequestTracingHandler.java | Updates channel context initialization to getOrCreate. |
| dd-java-agent/instrumentation/netty/netty-3.8/src/main/java/datadog/trace/instrumentation/netty38/ChannelFutureListenerInstrumentation.java | Updates future channel context initialization to getOrCreate. |
| dd-java-agent/instrumentation/mongo/mongo-common/src/main/java/datadog/trace/instrumentation/mongo/MongoCommandListener.java | Updates listener association to getOrPut. |
| dd-java-agent/instrumentation/karate/karate-2.0/src/main/java21/datadog/trace/instrumentation/karate2/KarateScenarioAdvice.java | Updates scenario execution context initialization to getOrCompute. |
| dd-java-agent/instrumentation/karate/karate-1.0/src/main/java/datadog/trace/instrumentation/karate/KarateExecutionInstrumentation.java | Updates scenario execution context initialization to getOrCompute. |
| dd-java-agent/instrumentation/kafka/kafka-clients-3.8/src/main/java17/datadog/trace/instrumentation/kafka_clients38/ProducerConstructorAdvice.java | Updates metadata state initialization to getOrCreate. |
| dd-java-agent/instrumentation/kafka/kafka-clients-3.8/src/main/java17/datadog/trace/instrumentation/kafka_clients38/MetadataUpdateBefore22Advice.java | Updates metadata state initialization to getOrCreate. |
| dd-java-agent/instrumentation/kafka/kafka-clients-3.8/src/main/java17/datadog/trace/instrumentation/kafka_clients38/MetadataUpdate22AndAfterAdvice.java | Updates metadata state initialization to getOrCreate. |
| dd-java-agent/instrumentation/kafka/kafka-clients-3.8/src/main/java17/datadog/trace/instrumentation/kafka_clients38/LegacyConstructorAdvice.java | Updates metadata state initialization to getOrCreate. |
| dd-java-agent/instrumentation/kafka/kafka-clients-3.8/src/main/java17/datadog/trace/instrumentation/kafka_clients38/ConstructorAdvice.java | Updates metadata state initialization to getOrCreate. |
| dd-java-agent/instrumentation/kafka/kafka-clients-0.11/src/main/java/datadog/trace/instrumentation/kafka_clients/MetadataInstrumentation.java | Updates metadata state initialization to getOrCreate. |
| dd-java-agent/instrumentation/kafka/kafka-clients-0.11/src/main/java/datadog/trace/instrumentation/kafka_clients/KafkaProducerInstrumentation.java | Updates metadata state initialization to getOrCreate. |
| dd-java-agent/instrumentation/kafka/kafka-clients-0.11/src/main/java/datadog/trace/instrumentation/kafka_clients/KafkaConsumerInfoInstrumentation.java | Updates metadata state initialization to getOrCreate. |
| dd-java-agent/instrumentation/jms/javax-jms-1.1/src/main/java/datadog/trace/instrumentation/jms/SessionInstrumentation.java | Updates session state association to getOrPut. |
| dd-java-agent/instrumentation/java/java-net/java-net-1.8/src/main/java/datadog/trace/instrumentation/java/net/HttpUrlConnectionInstrumentation.java | Updates URL connection state initialization to getOrCreate. |
| dd-java-agent/instrumentation/hibernate/hibernate-core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/SessionFactoryInstrumentation.java | Updates session state association to getOrPut. |
| dd-java-agent/instrumentation/hibernate/hibernate-core-3.3/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_3/SessionFactoryInstrumentation.java | Updates session/stateless session state association to getOrPut. |
| dd-java-agent/instrumentation/hibernate/hibernate-common/src/main/java/datadog/trace/instrumentation/hibernate/SessionMethodUtils.java | Updates state propagation to getOrPut. |
| dd-java-agent/instrumentation/graal/graal-native-image-20.0/src/main/java/datadog/trace/instrumentation/graal/nativeimage/NativeImageGeneratorRunnerInstrumentation.java | Updates native-image init list entry to WeakMapPerStore. |
| dd-java-agent/instrumentation/aws-java/aws-java-sqs-2.0/src/main/java/datadog/trace/instrumentation/aws/v2/sqs/SqsInterceptor.java | Updates ExecutionAttribute instance store init to getOrCreate. |
| dd-java-agent/instrumentation/aws-java/aws-java-sns-2.0/src/main/java/datadog/trace/instrumentation/aws/v2/sns/SnsInterceptor.java | Updates ExecutionAttribute instance store init to getOrCreate. |
| dd-java-agent/instrumentation/aws-java/aws-java-sfn-2.0/src/main/java/datadog/trace/instrumentation/aws/v2/sfn/SfnInterceptor.java | Updates ExecutionAttribute instance store init to getOrCreate. |
| dd-java-agent/instrumentation/aws-java/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2/TracingExecutionInterceptor.java | Updates ExecutionAttribute instance store init to getOrCreate. |
| dd-java-agent/instrumentation/aws-java/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2/AwsSdkClientDecorator.java | Updates ExecutionAttribute instance store init to getOrCreate. |
| dd-java-agent/instrumentation/aws-java/aws-java-s3-2.0/src/main/java/datadog/trace/instrumentation/aws/v2/s3/S3Interceptor.java | Updates ExecutionAttribute instance store init to getOrCreate. |
| dd-java-agent/instrumentation/aws-java/aws-java-eventbridge-2.0/src/main/java/datadog/trace/instrumentation/aws/v2/eventbridge/EventBridgeInterceptor.java | Updates ExecutionAttribute instance store init to getOrCreate. |
| dd-java-agent/instrumentation/aws-java/aws-java-dynamodb-2.0/src/main/java/datadog/trace/instrumentation/aws/v2/dynamodb/DynamoDbInterceptor.java | Updates ExecutionAttribute instance store init to getOrCreate. |
| dd-java-agent/instrumentation-testing/src/test/java/context/FieldInjectionTestInstrumentation.java | Updates test instrumentation to use getOrPut / getOrCreate. |
| dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/context/FieldBackedContextInjector.java | Redirects injected weak-get/put calls to WeakMapPerStore.get/put. |
| dd-java-agent/agent-ci-visibility/src/test/java/datadog/trace/civisibility/events/TestEventsHandlerImplTest.java | Updates tests to use StrongMapContextStore. |
| dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/utils/StrongMapContextStore.java | Adds a strong-reference ContextStore implementation for CI Visibility. |
| dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/utils/ConcurrentHashMapContextStore.java | Removes previous CI Visibility ContextStore implementation. |
| dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilitySystem.java | Switches CI Visibility default stores to StrongMapContextStore. |
| dd-java-agent/agent-ci-visibility/civisibility-instrumentation-test-fixtures/src/main/groovy/datadog/trace/civisibility/CiVisibilityInstrumentationTest.groovy | Updates test fixtures to use StrongMapContextStore. |
| dd-java-agent/agent-bootstrap/src/test/groovy/datadog/trace/bootstrap/InstanceStoreTest.groovy | Updates tests to InstanceStore.getOrCreate. |
| dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/WeakMapPerStore.java | Introduces weak-map-per-store helper/implementation and injection redirect methods. |
| dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/java/concurrent/ExecutorInstrumentationUtils.java | Updates task state initialization to getOrCreate. |
| dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/java/concurrent/ConcurrentState.java | Updates continuation state initialization to getOrCreate. |
| dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/InstanceStore.java | Renames putIfAbsent to getOrCreate and annotates nullable methods. |
| dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/FieldBackedContextStores.java | Removes weakGet/weakPut helpers (now in WeakMapPerStore). |
| dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/FieldBackedContextStore.java | Updates fallback weak-store integration to WeakMapPerStore and new ContextStore method names. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
More details
The only candidate concerns ContextInterpreter.java, which this PR does not change. No reportable defect remains for the ContextStore API cleanup.
🤖 Datadog Autotest · Commit a4a1653 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
There was a problem hiding this comment.
More details
The ContextStore API changes keep the same behavior in the changed implementations and callers. The child candidate is outside this PR diff, so it does not apply.
🤖 Datadog Autotest · Commit c117283 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
Build pipeline has failing jobs for 271725b:
What to do next?
DetailsSince those jobs are not marked as being allowed to fail, the pipeline will most likely fail. |
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
cc47520
into
master
What Does This Do
Refactors
ContextStore/InstanceStoreAPIs to clearer “get-or-*” semantics and cleans up javadoc and nullability annotations.Adjusts field-injection weak-map fallback to make it easier to swap in
GlobalObjectStore.Refactors weak-map fallback to not implement
ContextStore- it doesn't need to implement this interface and this refactoring reduces the number ofContextStoreimplementations to one for most deployments.Renames CI Visibility’s
ConcurrentHashMapContextStoretoStrongMapContextStore, to make clear it uses strong-references as opposed to the typical weak/field-injected store. Also removes an unnecessary capturing lambda.Motivation
Preparing the ground for future migration of the context-store implementation.
Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]