-
Notifications
You must be signed in to change notification settings - Fork 624
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
Add support for user defined attributes in OTLPHandler #1952
Add support for user defined attributes in OTLPHandler #1952
Conversation
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.
Thanks for trying to complete todo item. This was originally added because there is some clarification I wanted to get from logs sig and some questions on semantic conventions. I am not sure if we want to proceed with this as is.
@lonewolf3739 any update from the SIG on this one? Just wanted to make sure we can get this reviewed if it's still useful. |
This is fine. There were other changes when this PR opened and now it just has the extra attributes support. |
@@ -244,20 +244,58 @@ def force_flush(self, timeout_millis: int = 30000) -> bool: | |||
return True | |||
|
|||
|
|||
# skip natural LogRecord attributes | |||
# http://docs.python.org/library/logging.html#logrecord-attributes | |||
_RESERVED_ATTRS = frozenset( |
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.
We are skipping now to separate the user-defined extra attributes but we will revisit this later if needed.
@ocelotl anything needed on my end to merge this? |
@adriangb Please fix the lint. |
I'm working on it. Your setup / instructions in |
Well using your link I tried
Looking at the contrib-repo, I can see that there is no I'm also pretty confused as to why I need stuff from contrib to test (never mind lint) stuff in core. What is the point of having a |
Please make sure your branch is updated against |
@adriangb the |
Well I just went into the logs and fixed the 1 line pylint was complaining about. |
To avoid this #1952 (comment) in the future, I'd suggest you move away from long-lived feature branches. They're problematic for many reasons. |
I agree, the logs/metrics branches are a special case for the work around experimental features, but yes, long lived branches are terrible |
Looks like we're all ✅ now @ocelotl |
Let's see... |
I see tests that are still running will give this a bit more time |
Are those tests really running or is CI broken / stuck? It's been "running" for almost 2 hours with no output. Edit: it looks like at least |
@ocelotl can you please restart jobs here too? |
Sure |
@staticmethod | ||
def _get_attributes(record: logging.LogRecord) -> Attributes: | ||
return { | ||
k: v for k, v in vars(record).items() if k not in _RESERVED_ATTRS |
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.
Is extra
the only keyword that will be filtered in?
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.
Yes, that's how the stdlib logging library works.
Documentation: https://docs.python.org/3/library/logging.html#logging.Logger.debug (paragraph 2)
@ocelotl doesn't look like CI jobs were restarted, I'm still seeing the same |
Hmm... ok, seems like they have actually restarted now. Sorry for all the inconveniences, apparently the entire Github opentelemetry organization is having issues with CI. |
Looks like we're passing aside from a benchmark that says something is 7x slower (?). I don't think this PR would make anything 7x slower, so I'm guessing it's more strange CI stuff? |
Yes, seems like more trouble with Github-CI. The only thing I can do now is try running them again 🤷 I have also filed a ticket to Github regarding this problem. |
@codeboten this has different base branch. Same fix should applied to it as well. |
@lonewolf3739 correct, I created a PR here #2037 |
Re-running stuck jobs for this PR ✌️ |
Thank you! Looks like everything is passing now except for benchmarks, which I'm guessing is noise? All we're adding there is a single dict-comprehension. Except in some extreme case (all that happens in the entire program is logging and each log has 1000 user defined attributes), this should not change performance at all. |
We have seen performance issues with Pypy before, I'll try again. If it still refuses to pass we may have to take a look into the performance requirements for Pypy, it should be ok that they are lower than the rest. |
* Add initial overall structure and classes for logs sdk (#1894) * Add global LogEmitterProvider and convenience function get_log_emitter (#1901) * Add OTLPHandler for standard library logging module (#1903) * Add LogProcessors implementation (#1916) * Fix typos in test_handler.py (#1953) * Add support for OTLP Log exporter (#1943) * Add support for user defined attributes in OTLPHandler (#1952) * use timeout in force_flush (#2118) * use timeout in force_flush * fix lint * Update opentelemetry-sdk/src/opentelemetry/sdk/logs/export/__init__.py Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com> * fix lint Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com> * add a ConsoleExporter for logging (#2099) Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com> * Update SDK docs and Add example with OTEL collector logging (debug) exporter (#2050) * Fix exception in severity number transformation (#2208) * Fix exception with warning message transformation * Fix lint * Fix lint * fstring * Demonstrate how to set the Resource for LogEmitterProvider (#2209) * Demonstrate how to set the Resource for LogEmitterProvider Added a Resource to the logs example to make it more complete. Previously it was using the built-in Resource. Now it adds the service.name and service.instance.id attributes. The resulting emitted log records look like this: ``` Resource labels: -> telemetry.sdk.language: STRING(python) -> telemetry.sdk.name: STRING(opentelemetry) -> telemetry.sdk.version: STRING(1.5.0) -> service.name: STRING(shoppingcart) -> service.instance.id: STRING(instance-12) InstrumentationLibraryLogs #0 InstrumentationLibrary __main__ 0.1 LogRecord #0 Timestamp: 2021-10-14 18:33:43.425820928 +0000 UTC Severity: ERROR ShortName: Body: Hyderabad, we have a major problem. Trace ID: ce1577e4a703f42d569e72593ad71888 Span ID: f8908ac4258ceff6 Flags: 1 ``` * Fix linting * Use batch processor in example (#2225) * move logs to _logs (#2240) * move logs to _logs * fix lint * move log_exporter to _log_exporter as it's still experimental (#2252) Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com> Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Co-authored-by: Leighton Chen <lechen@microsoft.com> Co-authored-by: Tigran Najaryan <4194920+tigrannajaryan@users.noreply.github.com> Co-authored-by: Owais Lone <owais@users.noreply.github.com>
Description
This gives users the ability to inject custom attributes into emitted logs.
I think this should solve the discussion in https://github.com/open-telemetry/opentelemetry-python/pull/1903/files#r653092699
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
I added 2 tests for the functionality verifying that the attributes end up in the emitted LogRecord and that the user can specify a sub-key to pull attributes from.
Does This PR Require a Contrib Repo Change?
Checklist: