Socket
Socket
Sign inDemoInstall

@opentelemetry/instrumentation-undici

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-undici - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

11

build/src/types.d.ts

@@ -28,2 +28,3 @@ /// <reference types="node" />

statusCode: number;
statusText: string;
}

@@ -36,6 +37,12 @@ export interface IgnoreRequestFunction<T = UndiciRequest> {

}
export interface ResponseHookFunction<RequestType = UndiciResponse, ResponseType = UndiciResponse> {
(span: Span, info: {
request: RequestType;
response: ResponseType;
}): void;
}
export interface StartSpanHookFunction<T = UndiciRequest> {
(request: T): Attributes;
}
export interface UndiciInstrumentationConfig<RequestType = UndiciRequest> extends InstrumentationConfig {
export interface UndiciInstrumentationConfig<RequestType = UndiciRequest, ResponseType = UndiciResponse> extends InstrumentationConfig {
/** Not trace all outgoing requests that matched with custom function */

@@ -45,2 +52,4 @@ ignoreRequestHook?: IgnoreRequestFunction<RequestType>;

requestHook?: RequestHookFunction<RequestType>;
/** Function called once response headers have been received */
responseHook?: ResponseHookFunction<RequestType, ResponseType>;
/** Function for adding custom attributes before a span is started */

@@ -47,0 +56,0 @@ startSpanHook?: StartSpanHookFunction<RequestType>;

4

build/src/undici.d.ts
import { InstrumentationBase } from '@opentelemetry/instrumentation';
import { UndiciInstrumentationConfig } from './types';
export declare class UndiciInstrumentation extends InstrumentationBase {
export declare class UndiciInstrumentation extends InstrumentationBase<UndiciInstrumentationConfig> {
private _channelSubs;

@@ -11,5 +11,3 @@ private _recordFromReq;

enable(): void;
setConfig(config?: UndiciInstrumentationConfig): void;
protected _updateMetricInstruments(): void;
private _getConfig;
private subscribeToChannel;

@@ -16,0 +14,0 @@ private onRequestCreated;

@@ -32,3 +32,2 @@ "use strict";

this._recordFromReq = new WeakMap();
this.setConfig(config);
}

@@ -40,17 +39,24 @@ // No need to instrument files/modules

disable() {
if (!this._config.enabled) {
return;
}
super.disable();
this._channelSubs.forEach(sub => sub.channel.unsubscribe(sub.onMessage));
this._channelSubs.length = 0;
this._config.enabled = false;
}
enable() {
if (this._config.enabled) {
// "enabled" handling is currently a bit messy with InstrumentationBase.
// If constructed with `{enabled: false}`, this `.enable()` is still called,
// and `this.getConfig().enabled !== this.isEnabled()`, creating confusion.
//
// For now, this class will setup for instrumenting if `.enable()` is
// called, but use `this.getConfig().enabled` to determine if
// instrumentation should be generated. This covers the more likely common
// case of config being given a construction time, rather than later via
// `instance.enable()`, `.disable()`, or `.setConfig()` calls.
super.enable();
// This method is called by the super-class constructor before ours is
// called. So we need to ensure the property is initalized.
this._channelSubs = this._channelSubs || [];
// Avoid to duplicate subscriptions
if (this._channelSubs.length > 0) {
return;
}
this._config.enabled = true;
// This method is called by the `InstrumentationAbstract` constructor before
// ours is called. So we need to ensure the property is initalized
this._channelSubs = this._channelSubs || [];
this.subscribeToChannel('undici:request:create', this.onRequestCreated.bind(this));

@@ -62,11 +68,2 @@ this.subscribeToChannel('undici:client:sendHeaders', this.onRequestHeaders.bind(this));

}
setConfig(config = {}) {
super.setConfig(config);
if (config === null || config === void 0 ? void 0 : config.enabled) {
this.enable();
}
else {
this.disable();
}
}
_updateMetricInstruments() {

@@ -85,5 +82,2 @@ this._httpClientDurationHistogram = this.meter.createHistogram('http.client.request.duration', {

}
_getConfig() {
return this._config;
}
subscribeToChannel(diagnosticChannel, onMessage) {

@@ -106,6 +100,7 @@ const channel = diagch.channel(diagnosticChannel);

// - method is 'CONNECT'
const config = this._getConfig();
const config = this.getConfig();
const enabled = config.enabled !== false;
const shouldIgnoreReq = (0, instrumentation_1.safeExecuteInTheMiddle)(() => {
var _a;
return !config.enabled ||
return !enabled ||
request.method === 'CONNECT' ||

@@ -209,3 +204,3 @@ ((_a = config.ignoreRequestHook) === null || _a === void 0 ? void 0 : _a.call(config, request));

}
const config = this._getConfig();
const config = this.getConfig();
const { span } = record;

@@ -254,3 +249,5 @@ const { remoteAddress, remotePort } = socket;

};
const config = this._getConfig();
const config = this.getConfig();
// Execute the response hook if defined
(0, instrumentation_1.safeExecuteInTheMiddle)(() => { var _a; return (_a = config.responseHook) === null || _a === void 0 ? void 0 : _a.call(config, span, { request, response }); }, e => e && this._diag.error('caught responseHook error: ', e), true);
const headersToAttribs = new Set();

@@ -257,0 +254,0 @@ if ((_a = config.headersToSpanAttributes) === null || _a === void 0 ? void 0 : _a.responseHeaders) {

@@ -1,3 +0,3 @@

export declare const PACKAGE_VERSION = "0.4.0";
export declare const PACKAGE_VERSION = "0.5.0";
export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-undici";
//# sourceMappingURL=version.d.ts.map

@@ -20,4 +20,4 @@ "use strict";

// this is autogenerated file, see scripts/version-update.js
exports.PACKAGE_VERSION = '0.4.0';
exports.PACKAGE_VERSION = '0.5.0';
exports.PACKAGE_NAME = '@opentelemetry/instrumentation-undici';
//# sourceMappingURL=version.js.map
{
"name": "@opentelemetry/instrumentation-undici",
"version": "0.4.0",
"version": "0.5.0",
"description": "OpenTelemetry instrumentation for `undici` http client and Node.js fetch()",

@@ -52,3 +52,3 @@ "main": "build/src/index.js",

"nyc": "15.1.0",
"rimraf": "5.0.5",
"rimraf": "5.0.10",
"semver": "^7.6.0",

@@ -69,3 +69,3 @@ "test-all-versions": "6.1.0",

"sideEffects": false,
"gitHead": "ad8436d6a4174f2288cb939080cd4e74da94b0d7"
"gitHead": "19454560b49b669c8f9c0cca9fcc3308b415f2b1"
}

@@ -54,7 +54,8 @@ # OpenTelemetry Undici/fetch Instrumentation for Node.js

| ------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [`ignoreRequestHook`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/instrumentation-undici/src/types.ts#L63) | `IgnoreRequestFunction` | Undici instrumentation will not trace all incoming requests that matched with custom function. |
| [`requestHook`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/instrumentation-undici/src/types.ts#L65) | `RequestHookFunction` | Function for adding custom attributes before request is handled. |
| [`startSpanHook`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/instrumentation-undici/src/types.ts#L67) | `StartSpanHookFunction` | Function for adding custom attributes before a span is started. |
| [`requireParentforSpans`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/instrumentation-undici/src/types.ts#L69) | `Boolean` | Require a parent span is present to create new span for outgoing requests. |
| [`headersToSpanAttributes`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/instrumentation-undici/src/types.ts#L71) | `Object` | List of case insensitive HTTP headers to convert to span attributes. Headers will be converted to span attributes in the form of `http.{request\|response}.header.header-name` where the name is only lowercased, e.g. `http.response.header.content-length` |
| [`ignoreRequestHook`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/instrumentation-undici/src/types.ts#L73) | `IgnoreRequestFunction` | Undici instrumentation will not trace all incoming requests that matched with custom function. |
| [`requestHook`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/instrumentation-undici/src/types.ts#L75) | `RequestHookFunction` | Function for adding custom attributes before request is handled. |
| [`responseHook`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/instrumentation-undici/src/types.ts#L77) | `ResponseHookFunction` | Function for adding custom attributes after the response headers are received. |
| [`startSpanHook`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/instrumentation-undici/src/types.ts#L79) | `StartSpanHookFunction` | Function for adding custom attributes before a span is started. |
| [`requireParentforSpans`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/instrumentation-undici/src/types.ts#L81) | `Boolean` | Require a parent span is present to create new span for outgoing requests. |
| [`headersToSpanAttributes`](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/instrumentation-undici/src/types.ts#L83) | `Object` | List of case insensitive HTTP headers to convert to span attributes. Headers will be converted to span attributes in the form of `http.{request\|response}.header.header-name` where the name is only lowercased, e.g. `http.response.header.content-length` |

@@ -61,0 +62,0 @@ ### Observations

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc