azure-log-analytics-data-collector-client

Node.js wrapper for Azure Log Analytics data collector API

Usage no npm install needed!

<script type="module">
  import azureLogAnalyticsDataCollectorClient from 'https://cdn.skypack.dev/azure-log-analytics-data-collector-client';
</script>

README

Azure Log Analytics Data Collector Client

Test status

Node.JS wrapper for Azure Monitor HTTP Data Collector API.

Installation

npm install azure-log-analytics-data-collector-client

Or with yarn:

yarn add azure-log-analytics-data-collector-client

Usage

Javascript:

const {
  DataCollectorClient,
} = require("azure-log-analytics-data-collector-client");

const client = new DataCollectorClient(
  "WORKSPACE_ID",
  "PRIMARY_KEY_OR_SECONDARY_KEY"
);

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"
);

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 advanced settings -> connected resources -> Agents management.

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 _.

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 test

License

MIT