npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@digma/otel-js-instrumentation

v0.0.10

Published

This instrumentation package for JavaScript enriches the telemtry data collected by OpenTelemetry and helps Digma provide valuable insights and continuous feedback directly in the IDE.

Downloads

16

Readme

OpenTelemetry JS Instrumentation Digma

Digma facilitates continuous feedback by gleaning valuable insights from your code and displaying them in the IDE as you code.

This OpenTelemetry instrumentation package for Node.js helps Digma analyze your code by adding a number of OTEL resource attributes to the spans.

Prerequisites

  • Node version: 8 or above.

Installing the module

npm install @digma/otel-js-instrumentation

Usage

Setup

Instrumenting your OpenTelemetry resource

Digma needs to add a few more attributes to your OTEL Resource. To update your OTEL setup, simply use the provided digmaAttributes function as seen below:

const { digmaAttributes } = require('@digma/otel-js-instrumentation');

const sdk = new opentelemetry.NodeSDK({
  resource: new Resource({
    [SemanticResourceAttributes.SERVICE_NAME]: 'my-service',
    ...digmaAttributes({
      rootPath: __dirname,
    }),
  }),
  spanProcessor: new BatchSpanProcessor(exporter),
  instrumentations: [getNodeAutoInstrumentations()],
});

Adding instrumentation for specific server frameworks

Digma can also generate specifc insights based on the service framework you're using. To do that, we can add a simple middleware that will save the contexual information needed to map the tracing data to the underlying code in the Span attributes.

Follow the steps in the below links to add Digma's middlware, based on your server framework:

  • https://github.com/digma-ai/digma-instrumentation-express

For example, here is how you would use Digma's middlware with Express along with the standard OTEL middlware:

const { digmaRouteHandler } = require('@digma/instrumentation-express');

app = express();
app.use(digmaRouteHandler);
app.use('/users', users); // some router example

Exporting trace data to Digma

First, you need to have a Digma backend up and running. You can follow the instructions in the Digma project repository to quickly get set up using Docker.

You can use a standard OTLP exporter for local deployments:


const otlpExporter = new OTLPTraceExporter({
  url: 'http://localhost:5050',
});

Alternative, if you're already using a collector component you can simply modify its configuration file:

exporters:
...
otlp/digma:
    endpoint: "localhost:5050"
    tls:
      insecure: true
service:
  pipelines:
    traces:
      exporters: [otlp/digma, ...]

In both cases, set the endpoint value to the URL of the Digma backend.

That's it! You should be good to go.

Fine tuning and ehhancements

Digma allows you to set additional attributes while setting up the OpenTelemetry Resource to allow better observability visualization for commits, deployment environments, and more. All of these are optional, but can help provide more context to the collected traces:

| Options | Input Type | Attribute Key | Description | Default | | --- | --- | --- | --- | --- | | rootPath | string | [code.package.path, code.package.name]| rooPath describes the absolute path of the package.json file | None | digmaEnvironment | string | digma.environment | The Environment describes where the running process is deployed. (e.g production, staging, ci) | See the note on the Digma environment below. | commitId | string | scm.commit.id | The specific commit identifier of the running code. | | otherPackages | [] string | code.package.others | Specify additional satellite or infra packages to track | |

A note on the Digma environment

To support different configurations and deployment strategies, Digma provides a few ways to set the Digma environment. This list describes the order of precedence:

  1. If set, the DEPLOYMENT_ENV environment variable has the highest priority and always wins.
  2. If the environment variable is not set, Digma will use the digmaEnvironment attribute value passed to the digmaAttributes function.
  3. If no deployment environment is provided, we'll assume this is a local deployment environment and mark it using the local hostname. It will be visible only to this machine.