admin管理员组文章数量:1399260
I am struggling to send data to custom metrics from Browser API. Docs are clear on how to do it from Node.js, but in Browser context it looks like there is no other option but to send it via HTTP request.
Did anyone find a browser's api method to do that, or did datadog just skip this feature for browsers?
The datatog in my web app is configured the CDN way:
<script type="text/javascript" src=".js"></script>
<script>
DD_LOGS.init({
// config
});
</script>
I am struggling to send data to custom metrics from Browser API. Docs are clear on how to do it from Node.js, but in Browser context it looks like there is no other option but to send it via HTTP request.
Did anyone find a browser's api method to do that, or did datadog just skip this feature for browsers?
The datatog in my web app is configured the CDN way:
<script type="text/javascript" src="https://www.datadoghq-browser-agent/datadog-logs-us.js"></script>
<script>
DD_LOGS.init({
// config
});
</script>
Share
Improve this question
asked Mar 27 at 7:53
DanilMakarovDanilMakarov
598 bronze badges
2 Answers
Reset to default 2Datadog’s Browser SDK does not provide a direct API for sending custom metrics like the Node.js SDK does. Instead, the only way to send custom metrics from a browser is via HTTP requests to Datadog’s API.
Send a request to Datadog’s metrics API:
fetch("https://api.datadoghq/api/v1/series", {
method: "POST",
headers: {
"Content-Type": "application/json",
"DD-API-KEY": "your_api_key"
},
body: JSON.stringify({
series: [
{
metric: "custom.metric.name",
points: [[Date.now() / 1000, 42]], // timestamp in seconds, value
type: "gauge",
tags: ["env:production", "browser"]
}
]
})
}).then(response => response.json()).then(console.log).catch(console.error);
If you only need to track occurrences (not numerical metrics), use DD_LOGS.logger.info().
DD_LOGS.logger.info("Custom event", { custom_metric_value: 42 });
It seems like there is no other way but to use HTTP. The DOCS on submitting metrics are there.
本文标签: javascriptDatadog post custom metrics from BrowserStack Overflow
版权声明:本文标题:javascript - Datadog post custom metrics from Browser - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744105689a2591053.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论