-
Notifications
You must be signed in to change notification settings - Fork 894
fix(exporter/otlp): support non-standard types as attribute values and log body #5239
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
base: main
Are you sure you want to change the base?
Changes from all commits
d3e8060
3c182dd
00dab65
1543aa3
753a940
cabd22e
ed1470c
ee00ee8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| `opentelemetry-exporter-otlp-proto-common`, `opentelemetry-exporter-otlp-json-common`: support non-standard attribute value types (e.g. `pathlib.Path`) by coercing to string |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,20 @@ def _encode_value(value: Any, allow_null: bool = False) -> JSONAnyValue | None: | |
| ] | ||
| ) | ||
| ) | ||
| # Third-party instrumentation can inject arbitrary types that cannot be exhaustively | ||
| # whitelisted; stringify as a best-effort fallback so telemetry is not silently lost. | ||
| # None is excluded — it must be handled via allow_null=True at the call site. | ||
| if value is not None: | ||
| _logger.error( | ||
| "Invalid type %s for OTLP value; encoding as string. " | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: "attempting to encode as string" |
||
| "This is a bug in the instrumentation.", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to pass in the InstrumentationScope or the instrumentation name here, so we can reference it in this log message ? if not I'd leave out "this is a bug in the instrumentation library.." |
||
| type(value), | ||
| ) | ||
| # pylint: disable=broad-exception-caught | ||
| try: | ||
| return JSONAnyValue(string_value=str(value)) | ||
| except Exception: | ||
| pass | ||
| raise TypeError(f"Invalid type {type(value)} of value {value}") | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instrumentation should not do this, and ideally has type checking or something to ensure that it isn't doing this.. I would log an error here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added _logger.error() before the str() fallback in both json-common and proto-common