-
Notifications
You must be signed in to change notification settings - Fork 41
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
OtelRumConfig().setGlobalAttributes does not query the attribute supplier on every span or log creation #670
Comments
Hi @jpmuedano It seems like this could be related to a memory visibility issue. I'd recommend annotating your class' public class GlobalAttributeSupplierImpl : GlobalAttributeSupplier {
@Volatile /* Add this annotation to ensure that your changes to this field are visible from another thread */
private var attributes: Attributes = Attributes.empty()
/* ... */
} Also, I'd recommend to pass your supplier directly to the // Instead of this
val config = OtelRumConfig(
.setGlobalAttributes { attributesSupplier.get() }
// Try this
val config = OtelRumConfig(
.setGlobalAttributes(attributesSupplier) It's not a big deal, so you can leave it as is if you like, is just that when you use I hope it helps! |
Hello @LikeTheSalad
|
Can you provide more details on how is everything set up? (not just the To provide more context, the supplier that is provided in |
High level structure: class OpenTelemetryClient(
application: Application,
) {
val openTelemetry: OpenTelemetry
val attributeSupplier = GlobalAttributeSupplierImpl()
init {
// definition of attributes
attributeSupplier.createInitialAttributesWithKey(
listOf(
"dynamic_property",
),
)
val config = OtelRumConfig()
.setGlobalAttributes { attributeSupplier.get() }
// ...
val rumBuilder = OpenTelemetryRum.builder(application, config)
// ...
openTelemetry = rumBuilder
.build()
.openTelemetry
.run(GlobalOpenTelemetry::set)
}
fun updateDynamicProperty(value: Int) {
// declaration of attribute
attributeSupplier.update("dynamic_property", value)
}
} And the key operations on attributes: override fun createInitialAttributesWithKey(keys: List<String>) {
attributes = Attributes.builder()
.putAll(keys.associateWith { "" })
.build()
}
override fun update(key: String, value: String) {
val tempAttributes: MutableMap<String, Any> = mutableMapOf()
attributes.forEach { k, v ->
tempAttributes[k.key] = v
}
tempAttributes[key] = value
set(
Attributes.builder()
.putAll(tempAttributes)
.build(),
)
} |
Thank you for these details, I'll take a closer look. |
I've just tested it using our OTel demo app and I couldn't reproduce the issue. I've created this branch with my changes in case you'd like to take a look at how it was all set up. I'll explain the details below: I replicated your classes I then used those classes when initializing the RUM client here, where I also made the Once everything was set up, I modified the app's first screen to look like the following: I've added those 3 buttons, "Send span", "Send log" and "Update global attrs". The action for "Send log" is here and the action for "Update global attrs" is here for reference. For my tests I used the Elastic stack, although it should all work with any other vendor. If you would like to test it, you should set your vendor's endpoint params here. First I launched the app and clicked on "Send log", after a couple of seconds this is what I saw: At the top of the list, we see our log "A log body", when opening its attrs we can find the one that's set up here when initializing the RUM object. It's the Then I clicked on the "Update global attrs" button, which increases this counter and adds its most recent value to the Then I clicked on "Send log" again, and after a few seconds I opened the newest log at the top: And found: So I wasn't able to reproduce the issue. Please feel free to try it out to double-check. If you'd like you can also change my branch's code until the issue is reproducible there so that I can take another look. I hope it helps! |
Hello :) @LikeTheSalad
Based on the guidance given in issue #625, my understanding is that the
OtelRumConfig().setGlobalAttributes {}
should query theSupplier<Attributes>
on every span or log creation & populate the span attributes without having to explicitly set all attributes to every span through theSpanBuilder.setAllAttributes()
.For Example, the
OtelRumConfig()
:Where the supplier is a simple implementation including a setter:
Currently with this approach, I am not seeing the attributes populated on newly created spans, instead I have to include the attributes on every span builder to see the attributes reflected on every trace. I might be missing some other configuration for the global attribute supplier to work?
The text was updated successfully, but these errors were encountered: