opentelemetry-instrumentation-fetch-node
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,7 +0,14 @@ | ||
module.exports = { | ||
root: true, | ||
extends: 'gasbuddy', | ||
parserOptions: { | ||
project: './tsconfig.json' | ||
}, | ||
}; | ||
/** | ||
* This file is generated by coconfig. Do not edit it directly. | ||
* Instead, edit the coconfig.js or coconfig.ts file in your project root. | ||
* | ||
* See https://github.com/gas-buddy/coconfig for more information. | ||
* @version coconfig@0.13.3 | ||
*/ | ||
const configModule = require('@openapi-typescript-infra/coconfig'); | ||
const configItem = configModule.default || configModule.config || configModule; | ||
const { configuration } = configItem && configItem['.eslintrc.js']; | ||
const resolved = typeof configuration === 'function' ? configuration() : configuration; | ||
module.exports = resolved; |
@@ -1,16 +0,14 @@ | ||
module.exports = { | ||
bracketSpacing: true, | ||
bracketSameLine: true, | ||
singleQuote: true, | ||
trailingComma: 'all', | ||
// A person has his limits, and 80 is not it. | ||
printWidth: 100, | ||
overrides: [ | ||
{ | ||
files: '*.js', | ||
options: { | ||
parser: 'babel', | ||
}, | ||
}, | ||
], | ||
}; | ||
/** | ||
* This file is generated by coconfig. Do not edit it directly. | ||
* Instead, edit the coconfig.js or coconfig.ts file in your project root. | ||
* | ||
* See https://github.com/gas-buddy/coconfig for more information. | ||
* @version coconfig@0.13.3 | ||
*/ | ||
const configModule = require('@openapi-typescript-infra/coconfig'); | ||
const configItem = configModule.default || configModule.config || configModule; | ||
const { configuration } = configItem && configItem['.prettierrc.js']; | ||
const resolved = typeof configuration === 'function' ? configuration() : configuration; | ||
module.exports = resolved; |
@@ -0,9 +1,19 @@ | ||
/// <reference types="node" /> | ||
import { Instrumentation, InstrumentationConfig } from '@opentelemetry/instrumentation'; | ||
import { Span, TracerProvider } from '@opentelemetry/api'; | ||
import { MeterProvider } from '@opentelemetry/api-metrics'; | ||
import { MeterProvider, Span, TracerProvider } from '@opentelemetry/api'; | ||
interface FetchRequest { | ||
method: string; | ||
origin: string; | ||
path: string; | ||
headers: string; | ||
} | ||
interface FetchResponse { | ||
headers: Buffer[]; | ||
statusCode: number; | ||
} | ||
export interface FetchInstrumentationConfig extends InstrumentationConfig { | ||
onRequest?: (args: { | ||
request: any; | ||
request: FetchRequest; | ||
span: Span; | ||
additionalHeaders: Record<string, any>; | ||
additionalHeaders: Record<string, string | string[]>; | ||
}) => void; | ||
@@ -28,6 +38,17 @@ } | ||
getConfig(): InstrumentationConfig; | ||
onRequest({ request }: any): void; | ||
onHeaders({ request, response }: any): void; | ||
onDone({ request }: any): void; | ||
onError({ request, error }: any): void; | ||
onRequest({ request }: { | ||
request: FetchRequest; | ||
}): void; | ||
onHeaders({ request, response }: { | ||
request: FetchRequest; | ||
response: FetchResponse; | ||
}): void; | ||
onDone({ request }: { | ||
request: FetchRequest; | ||
}): void; | ||
onError({ request, error }: { | ||
request: FetchRequest; | ||
error: Error; | ||
}): void; | ||
} | ||
export {}; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FetchInstrumentation = void 0; | ||
/* | ||
@@ -9,11 +14,5 @@ * Portions from https://github.com/elastic/apm-agent-nodejs | ||
*/ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FetchInstrumentation = void 0; | ||
const node_diagnostics_channel_1 = __importDefault(require("node:diagnostics_channel")); | ||
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions"); | ||
const api_1 = require("@opentelemetry/api"); | ||
const api_metrics_1 = require("@opentelemetry/api-metrics"); | ||
// Get the content-length from undici response headers. | ||
@@ -62,3 +61,3 @@ // `headers` is an Array of buffers: [k, v, k, v, ...]. | ||
this.channelSubs = []; | ||
this.meter = api_metrics_1.metrics.getMeter(this.instrumentationName, this.instrumentationVersion); | ||
this.meter = api_1.metrics.getMeter(this.instrumentationName, this.instrumentationVersion); | ||
this.tracer = api_1.trace.getTracer(this.instrumentationName, this.instrumentationVersion); | ||
@@ -65,0 +64,0 @@ this.config = { ...config }; |
{ | ||
"name": "opentelemetry-instrumentation-fetch-node", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "OpenTelemetry Node 18+ native fetch automatic instrumentation package", | ||
@@ -8,3 +8,3 @@ "main": "build/index.js", | ||
"scripts": { | ||
"test": "jest", | ||
"test": "vitest", | ||
"build": "tsc -p tsconfig.build.json", | ||
@@ -34,22 +34,26 @@ "clean": "yarn dlx rimraf ./build", | ||
}, | ||
"config": { | ||
"coconfig": "@openapi-typescript-infra/coconfig" | ||
}, | ||
"devDependencies": { | ||
"@opentelemetry/sdk-trace-base": "^1.7.0", | ||
"@opentelemetry/sdk-trace-node": "^1.7.0", | ||
"@types/jest": "^29.2.0", | ||
"eslint": "^8.25.0", | ||
"eslint-config-gasbuddy": "^7.0.3", | ||
"husky": "^8.0.1", | ||
"jest": "^29.2.1", | ||
"jest-openapi": "^0.14.2", | ||
"lint-staged": "^13.0.3", | ||
"ts-jest": "^29.0.3", | ||
"typescript": "^4.8.4" | ||
"@openapi-typescript-infra/coconfig": "^4.2.1", | ||
"@opentelemetry/sdk-trace-base": "^1.17.0", | ||
"@opentelemetry/sdk-trace-node": "^1.17.0", | ||
"@typescript-eslint/eslint-plugin": "^6.7.4", | ||
"@typescript-eslint/parser": "^6.7.4", | ||
"coconfig": "^0.13.3", | ||
"eslint": "^8.51.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-import": "^2.28.1", | ||
"husky": "^8.0.3", | ||
"lint-staged": "^14.0.1", | ||
"typescript": "^5.2.2", | ||
"vitest": "^0.34.6" | ||
}, | ||
"dependencies": { | ||
"@opentelemetry/api": "^1.2.0", | ||
"@opentelemetry/api-metrics": "^0.33.0", | ||
"@opentelemetry/instrumentation": "^0.33.0", | ||
"@opentelemetry/semantic-conventions": "^1.7.0" | ||
"@opentelemetry/api": "^1.6.0", | ||
"@opentelemetry/instrumentation": "^0.43.0", | ||
"@opentelemetry/semantic-conventions": "^1.17.0" | ||
}, | ||
"packageManager": "yarn@3.2.4" | ||
} |
opentelemetry-instrumentation-fetch-node | ||
=============== | ||
![main CI](https://github.com/gas-buddy/opentelemetry-instrumentation-fetch-node/actions/workflows/nodejs.yml/badge.svg) | ||
[![TypeScript](https://badges.frapsoft.com/typescript/code/typescript.png?v=101)](https://github.com/ellerbrock/typescript-badges/) | ||
[![npm version](https://badge.fury.io/js/@gasbuddy%2Fopentelemetry-instrumentation-fetch-node.svg)](https://badge.fury.io/js/@gasbuddy%2Fopentelemetry-instrumentation-fetch-node) | ||
![main CI](https://github.com/gas-buddy/opentelemetry-instrumentation-fetch-node/actions/workflows/npm_publish.yml/badge.svg) | ||
[![npm version](https://badge.fury.io/js/@gasbuddy%2Fopentelemetry-instrumentation-fetch-node.svg)](https://badge.fury.io/js/opentelemetry-instrumentation-fetch-node) | ||
OpenTelemetry Node 18+ native fetch automatic instrumentation package. | ||
@@ -9,0 +11,0 @@ |
@@ -8,4 +8,4 @@ /* | ||
*/ | ||
import diagch from 'node:diagnostics_channel'; | ||
import diagch from 'node:diagnostics_channel'; | ||
import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; | ||
@@ -16,2 +16,5 @@ import { Instrumentation, InstrumentationConfig } from '@opentelemetry/instrumentation'; | ||
context, | ||
Meter, | ||
MeterProvider, | ||
metrics, | ||
propagation, | ||
@@ -25,3 +28,2 @@ Span, | ||
} from '@opentelemetry/api'; | ||
import { Meter, MeterProvider, metrics } from '@opentelemetry/api-metrics'; | ||
@@ -34,4 +36,20 @@ interface ListenerRecord { | ||
interface FetchRequest { | ||
method: string; | ||
origin: string; | ||
path: string; | ||
headers: string; | ||
} | ||
interface FetchResponse { | ||
headers: Buffer[]; | ||
statusCode: number; | ||
} | ||
export interface FetchInstrumentationConfig extends InstrumentationConfig { | ||
onRequest?: (args: { request: any; span: Span; additionalHeaders: Record<string, any> }) => void; | ||
onRequest?: (args: { | ||
request: FetchRequest; | ||
span: Span; | ||
additionalHeaders: Record<string, string | string[]>; | ||
}) => void; | ||
} | ||
@@ -64,3 +82,3 @@ | ||
private spanFromReq = new WeakMap<any, Span>(); | ||
private spanFromReq = new WeakMap<FetchRequest, Span>(); | ||
@@ -77,3 +95,4 @@ private tracer: Tracer; | ||
public readonly instrumentationDescription = 'Instrumentation for Node 18 fetch via diagnostics_channel'; | ||
public readonly instrumentationDescription = | ||
'Instrumentation for Node 18 fetch via diagnostics_channel'; | ||
@@ -104,6 +123,14 @@ private subscribeToChannel(diagnosticChannel: string, onMessage: diagch.ChannelListener) { | ||
enable(): void { | ||
this.subscribeToChannel('undici:request:create', (args) => this.onRequest(args)); | ||
this.subscribeToChannel('undici:request:headers', (args) => this.onHeaders(args)); | ||
this.subscribeToChannel('undici:request:trailers', (args) => this.onDone(args)); | ||
this.subscribeToChannel('undici:request:error', (args) => this.onError(args)); | ||
this.subscribeToChannel('undici:request:create', (args) => | ||
this.onRequest(args as { request: FetchRequest }), | ||
); | ||
this.subscribeToChannel('undici:request:headers', (args) => | ||
this.onHeaders(args as { request: FetchRequest; response: FetchResponse }), | ||
); | ||
this.subscribeToChannel('undici:request:trailers', (args) => | ||
this.onDone(args as { request: FetchRequest }), | ||
); | ||
this.subscribeToChannel('undici:request:error', (args) => | ||
this.onError(args as { request: FetchRequest; error: Error }), | ||
); | ||
} | ||
@@ -127,3 +154,3 @@ | ||
onRequest({ request }: any): void { | ||
onRequest({ request }: { request: FetchRequest }): void { | ||
// Don't instrument CONNECT - see comments at: | ||
@@ -157,3 +184,3 @@ // https://github.com/elastic/apm-agent-nodejs/blob/c55b1d8c32b2574362fc24d81b8e173ce2f75257/lib/instrumentation/modules/undici.js#L24 | ||
onHeaders({ request, response }: any): void { | ||
onHeaders({ request, response }: { request: FetchRequest; response: FetchResponse }): void { | ||
const span = this.spanFromReq.get(request); | ||
@@ -181,3 +208,3 @@ | ||
onDone({ request }: any): void { | ||
onDone({ request }: { request: FetchRequest }): void { | ||
const span = this.spanFromReq.get(request); | ||
@@ -190,3 +217,3 @@ if (span !== undefined) { | ||
onError({ request, error }: any): void { | ||
onError({ request, error }: { request: FetchRequest; error: Error }): void { | ||
const span = this.spanFromReq.get(request); | ||
@@ -193,0 +220,0 @@ if (span !== undefined) { |
@@ -8,3 +8,5 @@ { | ||
"__mocks__/**/*.ts", | ||
"coconfig.ts", | ||
"vitest.config.ts" | ||
] | ||
} |
{ | ||
"include": ["@types/**/*", "src/**/*", "__tests__/**/*", "__mocks__/**/*"], | ||
"include": [ | ||
"@types/**/*", | ||
"src/**/*", | ||
"__tests__/**/*", | ||
"__mocks__/**/*", | ||
"coconfig.ts", | ||
"vitest.config.ts" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"build", | ||
"build" | ||
], | ||
@@ -12,44 +19,25 @@ "ts-node": { | ||
"compilerOptions": { | ||
"lib": ["ES2022", "DOM"], | ||
"module": "CommonJS", | ||
"lib": [ | ||
"ES2022", | ||
"DOM" | ||
], | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"target": "ES2022", | ||
"declaration": true, /* Generates corresponding '.d.ts' file. */ | ||
"sourceMap": true, /* Generates corresponding '.map' file. */ | ||
"outDir": "./build", /* Redirect output structure to the directory. */ | ||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ | ||
// "removeComments": true, /* Do not emit comments to output. */ | ||
"incremental": true, /* Enable incremental compilation */ | ||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */ | ||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ | ||
"isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ | ||
/* Strict Type-Checking Options */ | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ | ||
// "strictNullChecks": true, /* Enable strict null checks. */ | ||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */ | ||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ | ||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ | ||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ | ||
/* Additional Checks */ | ||
// "noUnusedLocals": true, /* Report errors on unused locals. */ | ||
// "noUnusedParameters": true, /* Report errors on unused parameters. */ | ||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ | ||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ | ||
/* Module Resolution Options */ | ||
"moduleResolution": "NodeNext", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ | ||
"baseUrl": "./src", /* Base directory to resolve non-absolute module names. */ | ||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ | ||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ | ||
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ | ||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ | ||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ | ||
/* Source Map Options */ | ||
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ | ||
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ | ||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ | ||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ | ||
/* Experimental Options */ | ||
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ | ||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ | ||
"declaration": true, | ||
"sourceMap": true, | ||
"outDir": "./build", | ||
"incremental": true, | ||
"isolatedModules": true, | ||
"strict": true, | ||
"baseUrl": "./src", | ||
"allowSyntheticDefaultImports": true, | ||
"esModuleInterop": true, | ||
"experimentalDecorators": true, | ||
"paths": { | ||
"@/*": [ | ||
"./*" | ||
] | ||
} | ||
} | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
19
74044
13
18
485
+ Added@opentelemetry/instrumentation@0.43.0(transitive)
+ Added@types/shimmer@1.2.0(transitive)
+ Addedacorn@8.14.0(transitive)
+ Addedacorn-import-assertions@1.9.0(transitive)
+ Addedcjs-module-lexer@1.4.1(transitive)
+ Addedimport-in-the-middle@1.4.2(transitive)
+ Addedrequire-in-the-middle@7.4.0(transitive)
- Removed@opentelemetry/api-metrics@^0.33.0
- Removed@opentelemetry/api-metrics@0.33.0(transitive)
- Removed@opentelemetry/instrumentation@0.33.0(transitive)
- Removedrequire-in-the-middle@5.2.0(transitive)
Updated@opentelemetry/api@^1.6.0