Node.js wrapper for Azure Log Analytics data collector API
npm install azure-log-analytics-data-collector-clientNode.JS wrapper for Azure Monitor HTTP Data Collector API.
``sh`
npm install azure-log-analytics-data-collector-client
Or with yarn:
`sh`
yarn add azure-log-analytics-data-collector-client
Javascript:
`js
const {
DataCollectorClient,
} = require("azure-log-analytics-data-collector-client");
const client = new DataCollectorClient(
"WORKSPACE_ID",
"PRIMARY_KEY_OR_SECONDARY_KEY",
"OPTIONAL_HOST"
);
client
.send("MyLogs", [
{
level: "info",
message: "server starts",
},
])
.then(console.log);
`
Typescript:
`ts
import { DataCollectorClient } from "azure-log-analytics-data-collector-client";
const client = new DataCollectorClient(
"WORKSPACE_ID",
"PRIMARY_KEY_OR_SECONDARY_KEY",
"OPTIONAL_HOST"
);
client
.send("MyLogs", [
{
level: "info",
message: "server starts",
},
])
.then(console.log);
`
To get your WORKSPACE_ID and PRIMARY_KEY_OR_SECONDARY_KEY, in your workspace go to Agents management -> Log Analytics agent instructions.
The OPTIONAL_HOST is available for the ODS endpoint for your workspace cloud.ods.opinsights.azure.com
- Azure Public Cloud's is the default used if none is providedods.opinsights.azure.us
- Azure US Government's host has to be set to
To query your logs, go to the Logs tab of your workspace and use MyLogs_CL as query table name. Sample query:
``
MyLogs_CL
| where TimeGenerated > ago(24h)
| limit 10
Please note that only alphanumeric and underscore can be used as table name. the - in the table name will be replaced with _.
| Property | Optional | Description |
| --------- | :------: | ----------------------------------------------------------------------------------------------------------------------: |
| code | no | HTTP response code |
| status | no | HTTP response status |
| errorCode | yes | Error code from server |
| errorMsg | yes | Error message from server |
To run the integration test locally, grab the workspace id and the agent key and then run:
`sh``
LOG_ANALYTICS_WORKSPACE_ID=
MIT