英文:
How to send logs from a python application to Datadog using ddtrace?
问题
让我们假设我有一个使用cron
定期运行的Python例程。现在,假设我想将其日志发送到Datadog。我认为最简单的方法是通过Datadog的代理,例如使用ddtrace
...
import ddtrace
ddtrace.patch_all()
import logging
logger = logging.getLogger(__name__)
logger.warning("Dummy log")
...但这并不起作用。我尝试过使用DD_LOGS_INJECTION=true
和DD_LOGS_ENABLED=true
,但根据文档,似乎我需要配置一些内容,以便代理程序会追踪日志文件。但是,根据type: file
,我猜我可以发送日志而无需担心创建这些配置文件。
你会说什么是将日志发送到Datadog的最简单方法,以及如何从Python应用程序中执行这个操作?
英文:
Let's say that I have a python routine that runs periodically using cron
. Now, let's say that I want to send logs from it to Datadog. I thought that the simples way to do it would be via Datadog's agent, e.g. using ddtrace
...
import ddtrace
ddtrace.patch_all()
import logging
logger = logging.getLogger(__name__)
logger.warning("Dummy log")
...but this is not working. I've tried with both DD_LOGS_INJECTION=true
and DD_LOGS_ENABLED=true
but looking at the docs it seems that I have to configure something so the Agent will tail the log files. However, by looking at type: file
I'd guess that I could send logs without having to worry with creating those configuration files.
What would you say is the simplest way to send logs do Datadog and how to do that from a python application?
答案1
得分: 0
DD_LOGS_ENABLED
没有效果。我不得不直接编辑配置文件为logs_enabled: true
。
英文:
It turned out that DD_LOGS_ENABLED
has no effect. I had to directly edit the configuration file to logs_enabled: true
.
答案2
得分: -1
你需要设置你的API密钥和应用密钥:
datadog.initialize(
api_key='YOUR_API_KEY',
app_key='YOUR_APP_KEY',
logs_enabled=True)
英文:
You need to set your API key and app key:
datadog.initialize(
api_key='YOUR_API_KEY',
app_key='YOUR_APP_KEY',
logs_enabled=True)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论