Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@opentelemetry/sdk-node
Advanced tools
The @opentelemetry/sdk-node package is part of the OpenTelemetry project, which aims to provide a set of APIs, libraries, agents, and instrumentation to provide observability for applications. Specifically, the @opentelemetry/sdk-node package is designed for Node.js applications and allows developers to collect traces and metrics, and export them to various observability backends for analysis. This helps in monitoring applications, understanding performance bottlenecks, and troubleshooting issues.
Tracing
This feature allows the collection of trace data, which represents the lifecycle of a request through the system. The code sample initializes a tracer provider, sets up a span processor with a Jaeger exporter, and registers the provider. This setup enables the tracing of operations and requests, facilitating the monitoring and debugging of distributed systems.
const { NodeTracerProvider } = require('@opentelemetry/sdk-node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const provider = new NodeTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new JaegerExporter()));
provider.register();
Metrics
This feature enables the collection and export of metrics data, such as counters, gauges, and histograms. The code sample demonstrates how to set up a MeterProvider with a Prometheus exporter, which collects metrics data and makes it available for scraping by Prometheus at a specified port. This is useful for monitoring application performance and resource usage.
const { MeterProvider } = require('@opentelemetry/sdk-node');
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
const meterProvider = new MeterProvider({
exporter: new PrometheusExporter({ port: 9464 }),
interval: 1000
});
meterProvider.start();
Jaeger-client is a Node.js library for reporting tracing data to Jaeger, a distributed tracing system. While it is focused specifically on integration with Jaeger, @opentelemetry/sdk-node provides a more flexible approach, allowing for the export of traces to multiple backends, not just Jaeger.
Prom-client is a Node.js client library for Prometheus metrics. It is similar to the metrics functionality provided by @opentelemetry/sdk-node but is dedicated solely to Prometheus metrics collection and exposition. In contrast, @opentelemetry/sdk-node supports multiple metrics backends and integrates with the broader OpenTelemetry ecosystem for observability.
This package provides the full OpenTelemetry SDK for Node.js including tracing and metrics.
To get started you need to install @opentelemetry/sdk-node
, a metrics and/or tracing exporter, and any appropriate plugins for the node modules used by your application.
$ # Install the SDK
$ npm install @opentelemetry/sdk-node
$ # Install exporters and plugins
$ npm install \
@opentelemetry/exporter-jaeger \ # add tracing exporters as needed
@opentelemetry/exporter-prometheus # add metrics exporters as needed
@opentelemetry/plugin-http # add plugins as needed
$ # or install all officially supported core and contrib plugins
$ npm install @opentelemetry/plugins-node-core-and-contrib
Note: this example is for Node.js. See examples/tracer-web for a browser example.
Before any other module in your application is loaded, you must initialize the SDK. If you fail to initialize the SDK or initialize it too late, no-op implementations will be provided to any library which acquires a tracer or meter from the API. This example uses Jaeger and Prometheus, but exporters exist for other tracing backends.
const opentelemetry = require("@opentelemetry/sdk-node");
const { JaegerExporter } = require("@opentelemetry/exporter-jaeger");
const { PrometheusExporter } = require("@opentelemetry/exporter-prometheus");
const jaegerExporter = new JaegerExporter({
serviceName: 'my-service',
});
const prometheusExporter = new PrometheusExporter({ startServer: true });
const sdk = new opentelemetry.NodeSDK({
// Optional - if omitted, the tracing SDK will not be initialized
traceExporter: jaegerExporter,
// Optional - If omitted, the metrics SDK will not be initialized
metricExporter: prometheusExporter,
// See the Configuration section below for additional configuration options
});
// You can optionally detect resources asynchronously from the environment.
// Detected resources are merged with the resources provided in the SDK configuration.
sdk
.start()
.then(() => {
// Resources have been detected and SDK is started
})
Below is a full list of configuration options which may be passed into the NodeSDK
constructor;
Detect resources automatically from the environment using the default resource detectors. Default true
.
Use a custom context manager. Default: AsyncHooksContextManager
Use a custom propagator. Default: CompositePropagator using W3C Trace Context and Correlation Context
Use a custom logger. Default: Logging disabled
Default: INFO
Use a custom batcher for metrics. Default: UngroupedBatcher
Configure a metric exporter. If an exporter is not configured, the metrics SDK will not be initialized and registered.
Configure an interval for metrics export in ms. Default: 60,000 (60 seconds)
Configure plugins. By default, all plugins which are installed and in the Default Plugins List will be enabled.
Configure a resource. Resources may also be detected by using the autoDetectResources
method of the SDK.
Configure a custom sampler. By default all traces will be sampled.
Configure a trace exporter. If an exporter OR span processor is not configured, the tracing SDK will not be initialized and registered. If an exporter is configured, it will be used with a BatchSpanProcessor.
Configure tracing parameters. These are the same trace parameters used to configure a tracer.
Apache 2.0 - See LICENSE for more information.
FAQs
OpenTelemetry SDK for Node.js
The npm package @opentelemetry/sdk-node receives a total of 1,002,972 weekly downloads. As such, @opentelemetry/sdk-node popularity was classified as popular.
We found that @opentelemetry/sdk-node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.