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

Allow bytes as attributes #3605

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

adriangb
Copy link
Contributor

@adriangb adriangb requested a review from a team December 29, 2023 01:55
@adriangb adriangb force-pushed the allow-bytes-attributes branch from 14bdaf7 to 3cccbcd Compare December 29, 2023 02:13
@srikanthccv
Copy link
Member

We also need to update the exporter(s) code to support the bytes encoding. For instance, here for OTLP

def _encode_value(value: Any) -> PB2AnyValue:
if isinstance(value, bool):
return PB2AnyValue(bool_value=value)
if isinstance(value, str):
return PB2AnyValue(string_value=value)
if isinstance(value, int):
return PB2AnyValue(int_value=value)
if isinstance(value, float):
return PB2AnyValue(double_value=value)
if isinstance(value, Sequence):
return PB2AnyValue(
array_value=PB2ArrayValue(values=[_encode_value(v) for v in value])
)
elif isinstance(value, Mapping):
return PB2AnyValue(
kvlist_value=PB2KeyValueList(
values=[_encode_key_value(str(k), v) for k, v in value.items()]
)
)
raise Exception(f"Invalid type {type(value)} of value {value}")

@adriangb
Copy link
Contributor Author

Handled that case but I don't immediately see any others. Can you point them to me? Or can we just leave them as is and fix them as requested?

@srikanthccv
Copy link
Member

Let's encode to bytes as strings if the exporter/protocol doesn't support bytes.

  • OpenCensus doesn't support bytes. Lets encode as a string here
  • OTLP ✅
  • Prometheus values must be strings. Should be modified here
  • Zipkin only supports strings. Conversion here

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.

3 participants