Socket
Socket
Sign inDemoInstall

@grafana/agent-web

Package Overview
Dependencies
13
Maintainers
17
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @grafana/agent-web

Grafana JavaScript Agent instrumentations, metas, transports for web.


Version published
Weekly downloads
581
increased by102.44%
Maintainers
17
Install size
5.91 MB
Created
Weekly downloads
 

Readme

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

Last updated on 31 Oct 2022

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc