Skip to content
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

POC Global Attributes implementation #1181

Draft
wants to merge 2 commits into
base: feature/next-gen
Choose a base branch
from

Conversation

tonzhan2
Copy link
Contributor

@tonzhan2 tonzhan2 commented Feb 26, 2025

POC Implementation of global attributes feature.

  • added global attributes class and exposed API calls
  • implemented only basic set and remove for now
  • added global attributes to agent config
  • copied a global attribute span processor into the integration:agent:api module and modified slightly so it can process spans from the global attributes class located in integration:agent:api
  • tested both adding global attributes from agent config as well as adding and removing via sample app button during runtime

Copy link

@TomasChladekSL TomasChladekSL left a comment

Choose a reason for hiding this comment

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

Please take a look

val attributes: List<Attribute> get() = _attributes // Expose as immutable list

// this method definitely can be streamlined
operator fun set(key: Any, value: Any) {

Choose a reason for hiding this comment

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

IMHO, it would be better to write a function for each type. These "Any functions" are often leads into issues.

operator fun set(key: String, value: String) {
   remove(key)
   _attributes += Attribute.String(key, value)
}

}

fun remove(key: String) {
_attributes.removeAll { it.name == key }

Choose a reason for hiding this comment

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

There will be always at most one element with the key.

for (i in _attributes.indices)
   if (_attributes[i].name == key) {
      _attributes.removeAt(i)
     break
}


override fun onStart(parentContext: Context, span: ReadWriteSpan) {
// Fetch the current attributes from GlobalAttributes and apply them to the span
GlobalAttributes.instance.attributes.forEach { attribute ->

Choose a reason for hiding this comment

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

Please use forEachFast

import io.opentelemetry.sdk.trace.ReadableSpan
import io.opentelemetry.sdk.trace.SpanProcessor

class GlobalAttributeSpanProcessor2 : SpanProcessor {

Choose a reason for hiding this comment

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

Please remove GlobalAttributeSpanProcessor if possible

@tonzhan2
Copy link
Contributor Author

Thanks for the comments @TomasChladekSL , This is just a rough proof of concept to ensure everybody is on board with the approach, and not the final implementation. But I'll be sure to incorporate those things in the actual PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants