Giter Site home page Giter Site logo

getsentry / chartcuterie Goto Github PK

View Code? Open in Web Editor NEW
16.0 36.0 3.0 1.37 MB

NodeJS service to render charts as images. Uses node-canvas + echarts

License: Apache License 2.0

JavaScript 9.89% Dockerfile 1.29% TypeScript 87.90% Shell 0.92%
tag-lost-and-found-20230627

chartcuterie's Introduction

Chartcuterie

Chartcuterie offers fresh slices and dices of absolutely delectable graphs.

build npm


Sentry's Chartcuterie generates charts as images, specifically designed to aid in unfurling Sentry links with charts into slack, displaying useful charts in emails, and anywhere else outside of a browser environment where charts add valuable context.

echarts + node-canvas is used internally to produce the charts.

Looking for information on running Chartcuterie with Sentry? Check the develop docs.

Documentation

Chartcuterie can be run in two different modes

  • chartcuterie render - Accepts JSON data on stdin and writes out the produced image to stdout.

  • chartcuterie server - Runs the service as an HTTP API. It will accept a JSON body at POST /render and will respond with the image when successful.

Configuration

A configuration module is required to start Chartcuterie in any rendering mode. This module is used to specify how to transform data received to a valid EChart.Option object structure.

A simple configuration module might look like this:

import world from 'echarts/map/json/world.json';

const renderConfig = {
  /**
   * Each key in the configuration objects represents a rendering style
   * configurtion. When passing your render data to chartcuterie you'll use
   * this key to indicate what rendering config to use to produce your chart.
   */
  'myStyle:example': {
    key: 'myStyle:example',

    /**
     * The height and width of the produced image is specified as part of the
     * render configuration.
     */
    height: 200,
    width: 600,

    /**
     * This function is used to transform the `data` passed in your rendering
     * data JSON into a valid `EChart.Option`.
     */
    getOption: data => {
      return {series: data};
    },
  },

  // More rendering styles specified in this object.
}

const config = {
  renderConfig,
  /**
   * A version should be provided, which may be useful for observability
   * purposes.
   */
  version: '1.0.0-example.0',
  init: echarts => {
    echarts.registerMap('world', world);
  },
}

module.exports = config;

Configuration resolution

The configuration module may be specified as either a filepath or alternatively a HTTP URL. Specifying the file as a HTTP URL may be useful when your configuration file is produced by a different service, such is the case for Sentry, where the configuration is co-located with Sentry's frontend chart rendering modules.

IMPORTANT: When resolving the configuration over HTTP be ABSOLUTELY SURE that the configuration file can be trusted and will not contain any malicious JavaScript. The configuration file is evaluated with the same privileges the running instance of chartcuterie has!

Rendering charts

To render a chart in any rendering mode, you will need to supply some "rendering data". That is a JSON object that looks like this:

{
  /**
   * The request ID can be useful for tracing your render request
   */
  "requestId": "<some unique request identifier>",

  /**
   * The rendering style as specified in your configuration
   */
  "style": "myStyle:example",

  /**
   * The data object is totally arbitrary and is up to your configuration's
   * `getOption` function to translate it into a valid echarts series.
   */
  "data": "<anything you want here>"
}

Development

This project uses volta to manage the node toolchain, be sure to have Volta installed and configured. The Dockerfile specifies the system dependencies. If you want to run locally on macOS you'll need to install them yourself:

brew install cairo pango
  • yarn lint - Check for Typescript and Eslint errors / warnings.
  • yarn test - Run full test suite
  • yarn build - Builds the application
  • yarn watch - Watches source files for changes and recompiles using tsc on changes.

To start the service you will need to specify a config file. See the documentation above for examples of simple configuration you can use for testing.

Generally running like this is sufficient

node lib/index.js --config=exampleConfig.js render < example-data.json > example.png

License

Chartcuterie is licensed under the Apache License 2.0.

chartcuterie's People

Contributors

abhiprasad avatar asottile-sentry avatar byk avatar dashed avatar dependabot[bot] avatar evanpurkhiser avatar getsentry-bot avatar gggritso avatar jasonious avatar jonasba avatar joshuarli avatar lms24 avatar mattgauntseo-sentry avatar scttcper avatar shruthilayaj avatar vladanpaunovic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chartcuterie's Issues

[DS] Dog fooding sampling rules

Can we use this project to change the sampling rules, and or custom measurements functionalities?

we'd like to set the traces sample rate to not 1, create a release, then later change it as part of product demo to change the sample rate back and configure the rules in product.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.