azure-log-analytics-data-collector
v2.2.11
Published
Node.js wrapper for Azure Log Analytics data collector API
Maintainers
Readme
Azure Log Analytics Data Collector Client
Node.JS wrapper for Azure Monitor HTTP Data Collector API.
Installation
npm install azure-log-analytics-data-collector-clientOr with yarn:
yarn add azure-log-analytics-data-collector-clientUsage
Javascript:
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:
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.
- Azure Public Cloud's
ods.opinsights.azure.comis the default used if none is provided - Azure US Government's host has to be set to
ods.opinsights.azure.us
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 10Please note that only alphanumeric and underscore can be used as table name. the - in the table name will be replaced with _.
Response Object
| 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 |
Local Development
To run the integration test locally, grab the workspace id and the agent key and then run:
LOG_ANALYTICS_WORKSPACE_ID=<your_workspace_id> LOG_ANALYTICS_AGENT_KEY=<your_agent_key> yarn testLicense
MIT
