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

[Documentation] How can I enable python source logging to a mezmo log analysis destination? #109

Open
sabaimran opened this issue Aug 18, 2023 · 3 comments

Comments

@sabaimran
Copy link

sabaimran commented Aug 18, 2023

I haven't found the documentation here to be very straightforward. I think I'm supposed to create a new pipeline in order to establish a destination (in this case, the mezmo log analysis destination). When I added the ingestion key to the logger (via LogDNAHandler) in my python code, it doesn't end up sending out any logs.

Not sure what my source is supposed to be in this pipeline. I originally added HTTP since that seemed to be the closest match for using a code library, but that doesn't seem right as the key doesn't serve any purpose.

Any guidance here is appreciated.

@dkhokhlov
Copy link
Contributor

dkhokhlov commented Aug 18, 2023

@sabaimran
By default this library is sending logs to standard logging endpoint - Log Analysis destination (not Mezmo Pipeline):
https://github.com/logdna/python/blob/master/logdna/configs.py#L15
Once you have free Mezmo account opened and got the KEY you can use this code example to verify that it is sending logs and you can see them in live view of Web UI:
https://github.com/logdna/python#setup
Let me know if your goal is to use Pipeline.

@sabaimran
Copy link
Author

Awesome, thanks for the guidance @dkhokhlov . The goal is not to use pipeline -- I'd love to simply use it for Log Analysis. When I setup the script exactly as described in the setup snippet, I'm not able to actually see those logs anywhere. This is how I tested it:

(.venv) si@redwood logdna-test % python3
Python 3.11.4 (main, Jul 10 2023, 18:52:37) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> from logdna import LogDNAHandler
>>> key = "<REDACTED INGESTION KEY FROM MEZMO SETTINGS>
>>> logger = logging.getLogger('logdna')
>>> logger.setLevel(logging.INFO)
>>> test = LogDNAHandler(key)
>>> logger.addHandler(test)
>>> logger.info("test info message")

I don't see any errors, but I see a perpetual log-line from one of the underlying url libraries that indicates it's trying to connect when I run this in my application code. None of the logs seem to show up in the Mezmo dashboard.

@dkhokhlov
Copy link
Contributor

dkhokhlov commented Aug 18, 2023

Looks like as issue with KEY. Lets try sending sample log line with curl:

curl "https://logs.logdna.com/logs/ingest?hostname=MYHOST&now=$(date +%s)000" -u "XXXXXXXXXXXXXXXXXXXX:" --header "Content-Type: application/json; charset=UTF-8" -d "{\"lines\":[{\"line\":\"This is a sample test log statement\",\"timestamp\":\"2018-11-02T10:53:06+00:00\",\"level\":\"INFO\",\"app\":\"myapp\"}]}"
  • replace XXXXX with your key. note terminating ":".

Expected:

{"batchID":"704a9733-5dac-4113-816e-bdb0a0fcda39:4400:ld81","status":"ok"}

and you should see the sample line in live view.

full description of this method is here:
https://cloud.ibm.com/docs/log-analysis?topic=log-analysis-ingest

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

No branches or pull requests

2 participants