Skip to content

Feedback on ExtendedAttributes API #7323

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

Open
fandreuz opened this issue May 6, 2025 · 0 comments
Open

Feedback on ExtendedAttributes API #7323

fandreuz opened this issue May 6, 2025 · 0 comments
Labels
Bug Something isn't working

Comments

@fandreuz
Copy link
Contributor

fandreuz commented May 6, 2025

Hi @jack-berg, thanks for working on #7123. As discussed below the PR, I'll drop here some feedback I collected while working on open-telemetry/opentelemetry-java-instrumentation#8354. There may be more, I'll update the issue if I think about something else.

InternalExtendedAttributeKeyImpl#toString should contain type information

The current implementation makes inspecting test failures quite confusing:

    Expecting map:
      {string1="1", string2="2"}
    to contain entries:
      [map={string1="1", string2="2"}]
    but could not find the following map entries:
      [map={string1="1", string2="2"}]

I think it would make sense to embed the additional information in the string.

ExtendedAttributesBuilder#put(String, Object)

Sometimes the type information at compile time is erased due to attributes being pushed into a Map<String, Object> (e.g. Log4j's ThreadContext#getThreadContextMap). Thus, we have to write something like this:

    if (value instanceof String) {
      attributes.put(
          (ExtendedAttributeKey<String>) keyProvider.apply(key, ExtendedAttributeType.STRING),
          (String) value);
    } else if (value instanceof Boolean) {
      attributes.put(
          (ExtendedAttributeKey<Boolean>) keyProvider.apply(key, ExtendedAttributeType.BOOLEAN),
          (Boolean) value);
[...]

This same logic might be duplicated in many different places, increasing the likelihood of mistakes. Example here. Is there a better way to do it in the current implementation?

It would be nice to have a public utility to expose InternalExtendedAttributeKeyImpl.create

Sometimes it's useful to use this factory directly, e.g. here. Should I consider it public API? I guess not.

It would be nice to extend the assertion framework for ExtendedAttributes

Writing tests for ExtendedAttributes is possible at the moment, but a bit cumbersome. I guess LogRecordDataAssert will be updated only when the API stabilizes, right?

@fandreuz fandreuz added the Bug Something isn't working label May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant