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

@safaricom-mxl/node

v0.1.32

Published

Safaricom MXL NodeJS wrapper around OpenTelemetry APIs

Downloads

386

Readme

🚀 NodeJs Otel

@safaricom-mxl/nodejs-otel is a simple and easy-to-use package that sets up your tracing configuration.

💡 Use this package to quickly instrument your NodeJS applications and get started with OpenTelemetry!

Installation

npm install @safaricom-mxl/nodejs-otel

Usage

To configure OpenTelemetry SDK, call the registerOTel in the instumentation.ts:

import { registerOTel } from "@safaricom-mxl/nodejs-otel";

export function register() {
  // Register the OpenTelemetry.
  registerOTel("your-service-name");
}

To create custom spans in your code, use the OpenTelemetry API:

import { trace } from "@opentelemetry/api";

// Now you can use the OpenTelemetry APIs
const span = trace.getTracer("your-component").startSpan("your-operation");

API Reference

registerOTel(serviceName: string)

Registers the OpenTelemetry SDK with the specified service name and the default configuration.

  • serviceName: The name of your service, used as the app name in many OpenTelemetry backends.

registerOTel(config: Configuration)

Registers the OpenTelemetry SDK with the specified configuration. Configuration options include:

  • serviceName: The name of your service, used as the app name in many OpenTelemetry backends.
  • attributes: The resource attributes. By default, @safaricom-mxl/nodejs-otel configures relevant Safaricom MXL attributes based on the environment, such as env, safaricom-mxl.runtime, safaricom-mxl.host, etc.
  • instrumentations: A set of instrumentations. By default, @safaricom-mxl/nodejs-otel configures "fetch" instrumentation.
  • instrumentationConfig: Customize configuration for predefined instrumentations:
    • fetch: Customize configuration of the predefined "fetch" instrumentation:
      • ignoreUrls: A set of URL matchers (string prefix or regex) that should be ignored from tracing. By default all URLs are traced. Example: fetch: { ignoreUrls: [/example.com/] }.
      • propagateContextUrls: A set of URL matchers (string prefix or regex) for which the tracing context should be propagated (see propagators). By default the context is propagated only for the deployment URLs, all other URLs should be enabled explicitly. Example: fetch: { propagateContextUrls: [ /my.api/ ] }.
      • dontPropagateContextUrls: A set of URL matchers (string prefix or regex) for which the tracing context should not be propagated (see propagators). This allows you to exclude a subset of URLs allowed by the propagateContextUrls.
      • resourceNameTemplate: A string for the "resource.name" attribute that can include attribute expressions in {}. Example: fetch: { resourceNameTemplate: "{http.host}" }.
      • The fetch instrumentation also allows the caller to pass relevant telemetry parameters via fetch(..., { opentelemetry: {} }) argument (requires Next 14.1.1 or above), which may include the following fields:
        • ignore: boolean: overrides ignoreUrls for this call.
        • propagateContext: boolean: overrides propagateContextUrls for this call.
        • spanName: string: overrides the computed span name for this call.
        • attributes: Attributes: overrides the computed attributes for this call.
  • propagators: A set of propagators that may extend inbound and outbound contexts. By default, @safaricom-mxl/nodejs-otel configures W3C Trace Context propagator.
  • traceSampler: The sampler to be used to decide which requests should be traced. By default, all requests are traced. This option can be changed to, for instance, only trace 1% of all requests.
  • spanProcessors and traceExporter: The export mechanism for traces. By default, @safaricom-mxl/nodejs-otel configures the best export mechanism for the environment. For instance, if a tracing integrations is configured on Safaricom MXL, this integration will be automatically used for export; otherwise an OTLP exporter can be used if configured in environment variables.

See API for more details.

References