Skip to content

Conversation

@Arunodoy18
Copy link

Summary

This PR addresses two important issues in OpenTelemetry Java Instrumentation:

  1. SPI service file relocation during javaagent shading (Fixes Hydrate custom attributes http.server.request.duration #14825)
  2. Missing Kafka messaging receive instrumentation configuration in Spring Boot autoconfigure

Problem 1: SPI Service File Relocation

When classes are relocated during javaagent shading (e.g., io.opentelemetry.instrumentation to io.opentelemetry.javaagent.shaded.instrumentation), the corresponding SPI files in META-INF/services/ were not being renamed to match the new class locations.

This caused extensions to require shaded class names instead of original names when using InstrumenterCustomizerProvider and HttpClientUrlTemplateCustomizer.

Problem 2: Kafka Messaging Configuration Gap

The Kafka instrumentation autoconfiguration was missing the ability to configure messagingReceiveInstrumentationEnabled from the property otel.instrumentation.messaging.experimental.receive-telemetry.enabled, making it impossible to control creation of separate spans in Spring Boot Kafka consumers.

Solutions

SPI Fix

  • Added eachFile transformation to Shadow plugin configuration in both javaagent-shadowing.gradle.kts and muzzle-check.gradle.kts
  • Automatically renames SPI service files to match relocated class names
  • Added test SPI file to demonstrate functionality

Kafka Configuration Fix

  • Added setMessagingReceiveInstrumentationEnabled() call in KafkaInstrumentationAutoConfiguration
  • Uses the standard property otel.instrumentation.messaging.experimental.receive-telemetry.enabled
  • Follows the same pattern as other messaging instrumentations (JMS, Pulsar, etc.)

Testing

  • SPI fix includes test service file that demonstrates the relocation functionality
  • Kafka fix follows established patterns used in other messaging instrumentations

Files Changed

  • conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts
  • gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts
  • javaagent-tooling/src/main/resources/META-INF/services/io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpClientUrlTemplateCustomizer
  • instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/kafka/KafkaInstrumentationAutoConfiguration.java

When classes are relocated during shading (e.g., io.opentelemetry.instrumentation
to io.opentelemetry.javaagent.shaded.instrumentation), the corresponding SPI files
in META-INF/services/ were not being renamed to match the new class locations.

This fix adds an eachFile block to the Shadow plugin configuration to rename
SPI service files when shading is enabled. Now extensions can use the correct
shaded class names in their SPI files.

Fixes issue where InstrumenterCustomizerProvider and HttpClientUrlTemplateCustomizer
SPI files needed to reference shaded class names but weren't being automatically
renamed during the build process.

Changes:
- Added eachFile transformation to javaagent-shadowing.gradle.kts
- Added eachFile transformation to muzzle-check.gradle.kts
- Added test SPI file to demonstrate functionality

Resolves issue open-telemetry#14825
…oconfigure

The Kafka instrumentation autoconfiguration was missing the ability to configure
messagingReceiveInstrumentationEnabled from the property
'otel.instrumentation.messaging.experimental.receive-telemetry.enabled'.

This is required to control creation of separate spans in Spring Boot
autoconfiguration for Kafka consumers.

Changes:
- Added setMessagingReceiveInstrumentationEnabled() call in KafkaInstrumentationAutoConfiguration
- Uses the standard property 'otel.instrumentation.messaging.experimental.receive-telemetry.enabled'
- Follows the same pattern as other messaging instrumentations (JMS, Pulsar, etc.)

Fixes the missing configuration that was preventing proper control of Kafka
consumer span creation in Spring Boot applications.
@Arunodoy18 Arunodoy18 requested a review from a team as a code owner December 3, 2025 16:52
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 3, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@github-actions github-actions bot added the test native This label can be applied to PRs to trigger them to run native tests label Dec 3, 2025
.getBoolean("otel.instrumentation.kafka.experimental-span-attributes", false))
config.getBoolean("otel.instrumentation.kafka.experimental-span-attributes", false))
.setMessagingReceiveInstrumentationEnabled(
config.getBoolean("otel.instrumentation.messaging.experimental.receive-telemetry.enabled", false))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should open separate PRs for these changes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i will make sure it happens next time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If your intent is to get something merged then remove everything else from this PR or move just this part to a separate PR. Also add this configuration option to https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/spring/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Context propagation was not working correctly for batch messages in RocketMQ 5.0+
because all messages in a batch were sharing the same receive span context instead
of each message having its own context extracted from message properties.

Changes:
- Modified ReceiveSpanFinishingCallback to extract individual context for each
  message in the batch using MessageMapGetter to read trace headers
- Each message now gets its own properly linked context for correct tracing
- Re-enabled testRocketmqProduceAndBatchConsume test for latest dependencies

This fixes the issue where batch message consumers would not properly propagate
trace context from producers, breaking distributed tracing for RocketMQ batch
message processing in versions 5.3.4+.

Resolves the disabled test from open-telemetry#15512
// Extract context from individual message properties (trace headers)
Context messageContext = RocketMqSingletons.propagators()
.getTextMapPropagator()
.extract(context, messageView, MessageMapGetter.INSTANCE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this would fix #15526. rocketmq-client-5.0 module is the instrumentation for org.apache.rocketmq:rocketmq-client-java while rocketmq-client-4.8 module is for org.apache.rocketmq:rocketmq-client. So you need to focus on the rocketmq-client-4.8 module to resolve this issue.

relocate("application.java.util.logging", "java.util.logging")

// Rename SPI service files to match relocated class names
eachFile {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dis some AI com up with this? If so I'd suggest you to give up on #15513

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test native This label can be applied to PRs to trigger them to run native tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants