Skip to content

Add logging integrations with logging and structlog#586

Merged
basepi merged 28 commits into
elastic:masterfrom
basepi:logging520
Sep 17, 2019
Merged

Add logging integrations with logging and structlog#586
basepi merged 28 commits into
elastic:masterfrom
basepi:logging520

Conversation

@basepi

@basepi basepi commented Sep 9, 2019

Copy link
Copy Markdown
Contributor
  • Added new entries to the public API as helpers to retrieve transaction, trace, and span IDs
  • Added new ways to add APM tracing fields to logs:
    • logging filter
    • structlog processor
    • automatic log_record_factory for python 3.2+
  • Added new "Logging Integrations" documentation
  • Added documentation around ingest for log correlation
  • Added tests for the filter, processor, and log_record_factory

Resolves #520

@basepi basepi requested a review from beniwohli September 9, 2019 20:47

@axw axw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking good!

Comment thread docs/logging.asciidoc
Comment thread elasticapm/traces.py Outdated

@beniwohli beniwohli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a few nitpicks :) other than that, great stuff! We probably need to iterate on the docs a bit, it's going to be a fine line between being useful enough and not replicating a lot of logging and logstash/ingest docs :D

Comment thread docs/logging.asciidoc
Comment thread docs/logging.asciidoc
Comment thread elasticapm/handlers/logging.py Outdated
Comment thread elasticapm/handlers/logging.py Outdated
@basepi

basepi commented Sep 10, 2019

Copy link
Copy Markdown
Contributor Author

I still want to add a LogRecord factory for Python 3's setLogRecordFactory -- it will be enabled by default but you can turn it off via a config value.

I also still need to do some more documentation work around json logging, logstash grok, etc, for getting these new fields into ES in a useful way.

Otherwise I've implemented the other review comments, and will do the above ^ tomorrow.

@beniwohli beniwohli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work! Missed a couple things in my first review, sorry about that!

Comment thread docs/api.asciidoc Outdated
Comment thread elasticapm/handlers/logging.py Outdated
Comment thread elasticapm/handlers/logging.py Outdated
Comment thread tests/handlers/logging/logging_tests.py Outdated
@basepi

basepi commented Sep 13, 2019

Copy link
Copy Markdown
Contributor Author

Unless I forgot something major, I think this PR is ready for final review.

@beniwohli beniwohli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great job on the documentation, I'll add @bmorelli25 to the reviewers to have a look at them too

Other than a few small things, I think this can be merged! Awesome job!

Comment thread docs/logging.asciidoc Outdated
Comment thread docs/logging.asciidoc
Comment thread docs/logging.asciidoc Outdated
Comment thread elasticapm/base.py Outdated
Comment thread elasticapm/base.py Outdated
Comment thread elasticapm/handlers/logging.py Outdated

@bmorelli25 bmorelli25 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great work @basepi! I have some comments below. I'd recommend taking a look at #586 (comment) first. Let me know if you have any questions!

Also, just in case you were unaware, each PR generates a doc build that's available to easily see documentation changes: http://apm-agent-python_586.docs-preview.app.elstc.co/diff. There is a bug where the diff is duplicated, so only focus on the first links.

Comment thread docs/logging.asciidoc Outdated
Comment thread docs/logging.asciidoc Outdated
Comment thread docs/logging.asciidoc Outdated
Comment thread docs/logging.asciidoc Outdated
Comment thread docs/logging.asciidoc Outdated
Comment thread docs/logging.asciidoc Outdated
Comment thread docs/logging.asciidoc Outdated
Comment thread docs/logging.asciidoc Outdated
Comment thread docs/logging.asciidoc Outdated
Comment thread docs/logging.asciidoc Outdated
Comment thread docs/logging.asciidoc Outdated
Comment thread docs/logging.asciidoc Outdated
@bmorelli25

Copy link
Copy Markdown
Member

I just had another thought about this PR. I'm currently working on documentation for the integration between the APM UI and the Logs UI. The idea for those docs was to include the Log correlation instructions in a central location. You can see the draft I have here: https://github.com/elastic/apm-server/pull/2672/files#diff-e5d2431c1637befb5513a06f10499bfb. Right now I haven't put any work into it. It's just copy/pasted from the logs documentation, and probably doesn't make any sense in this context.

I'm wondering what your thoughts would be on the log correlation documentation living there vs in the Agent repos. It looks like for structured logs you use a logging package specific to python, but for unstructured the solution is more flexible and might apply to other agents as well? Please correct me if I'm wrong. Would like @beniwohli's thoughts as well.

@beniwohli

beniwohli commented Sep 13, 2019

Copy link
Copy Markdown
Contributor

@bmorelli25 I think everything starting from https://github.com/elastic/apm-agent-python/pull/586/files#diff-b9aa18d4f6625af66a2ba37d4263e914R118 could live in a central documentation, with the assumption that all other agents can replicate the format that @basepi proposed.

@basepi basepi self-assigned this Sep 13, 2019
@basepi basepi removed their assignment Sep 13, 2019
@basepi

basepi commented Sep 13, 2019

Copy link
Copy Markdown
Contributor Author

Yeah similar documentation could work for other languages. Obviously getting the unstructured log lines to the parseable state will differ based on the language/logging library the user is working with. If we ended up centralizing it, I'd just replace ours with a link to the central docs.

@bmorelli25

Copy link
Copy Markdown
Member

Great, thanks. Let's stick with this format for now and I'll update if/when we get to that point.

Comment thread docs/logging.asciidoc Outdated
Because of the dynamic insertion in Client, this test was failing
on the wider integration tests (perhaps because it had been inserted
on previous test runs? I'm actually not sure). Anyway, we test
that it works with an instantiated Client so I think this test is
unnecessary.
@basepi

basepi commented Sep 16, 2019

Copy link
Copy Markdown
Contributor Author

Alright, I've incorporated all feedback and have the tests back to green. This is ready for final approval.

Comment thread docs/logging.asciidoc Outdated

@bmorelli25 bmorelli25 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work @basepi! Other than Andrew's recommendation above, docs LGTM!

@beniwohli beniwohli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a few minor documentation bits. Feel free to merge after that!

Comment thread docs/api.asciidoc Outdated
Comment thread docs/configuration.asciidoc Outdated
Comment thread docs/logging.asciidoc Outdated
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.

Integration with log libraries to be able to tag log messages with trace/transaction

4 participants