Socket
Book a DemoInstallSign in
Socket

@grafana/agent-web

Package Overview
Dependencies
Maintainers
17
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@grafana/agent-web

Grafana JavaScript Agent instrumentations, metas, transports for web.

0.6.0
latest
Source
npmnpm
Version published
Weekly downloads
155
66.67%
Maintainers
17
Weekly downloads
 
Created
Source

@grafana/agent-web

DEPRECATED Project has been moved to @grafana/faro-web-sdk

Instrumentations, metas and transports for web applications.

Warning: currently pre-release and subject to frequent breaking changes. Use at your own risk.

Instrumentations

  • console - captures messages logged to console global object. Only warn, info and error levels by default.
  • errors - captures unhandled top level exceptions
  • web-vitals - captures performance metrics reported by web vitals API

Metas

  • browser - captures browser metadata: name, version, etc
  • page - captures current URL

Transports

  • console - logs events to global console
  • fetch - sends events over HTTP to a backend

Example

Basic set up, will automatically report errors and web vitals:

import { initializeGrafanaAgent } from '@grafana/agent-web';

const agent = initializeGrafanaAgent({
  url: 'https://agent.myapp/collect',
  apiKey: 'secret',
  app: {
    name: 'frontend',
    version: '1.0.0',
  },
});

// send a log message
agent.api.pushLog(['hello world']);

// will be captured
throw new Error('oh no');

// push error manually
agent.api.pushError(new Error('oh no'));

With OTel tracing and browser console capture:

import { TracingInstrumentation } from '@grafana/agent-tracing-web';
import { ConsoleInstrumentation, initializeGrafanaAgent, getWebInstrumentations } from '@grafana/agent-web';

const agent = initializeGrafanaAgent({
  url: 'https://agent.myapp/collect',
  apiKey: 'secret',
  instrumentations: [...getWebInstrumentations({ captureConsole: true }), new TracingInstrumentation()],
  app: {
    name: 'frontend',
    version: '1.0.0',
  },
});

// start a span
agent.api
  .getOTEL()
  ?.trace.getTracer('frontend')
  .startActiveSpan('hello world', (span) => {
    // send a log message
    agent.api.pushLog(['hello world']);
    span.end();
  });

// will be captured
throw new Error('oh no');

FAQs

Package last updated on 31 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.