@opentelemetry/instrumentation-http
Advanced tools
Comparing version 0.25.1-alpha.24 to 0.26.0
@@ -13,2 +13,3 @@ /// <reference types="node" /> | ||
private readonly _version; | ||
private _headerCapture; | ||
constructor(config?: HttpInstrumentationConfig & InstrumentationConfig); | ||
@@ -50,3 +51,4 @@ private _getConfig; | ||
private _callStartSpanHook; | ||
private _createHeaderCapture; | ||
} | ||
//# sourceMappingURL=http.d.ts.map |
@@ -36,2 +36,3 @@ "use strict"; | ||
this._version = process.versions.node; | ||
this._headerCapture = this._createHeaderCapture(); | ||
} | ||
@@ -43,2 +44,3 @@ _getConfig() { | ||
this._config = Object.assign({}, config); | ||
this._headerCapture = this._createHeaderCapture(); | ||
} | ||
@@ -190,2 +192,4 @@ init() { | ||
} | ||
this._headerCapture.client.captureRequestHeaders(span, header => request.getHeader(header)); | ||
this._headerCapture.client.captureResponseHeaders(span, header => response.headers[header]); | ||
api_1.context.bind(api_1.context.active(), response); | ||
@@ -241,3 +245,3 @@ this._diag.debug('outgoingRequest on response()'); | ||
const method = request.method || 'GET'; | ||
instrumentation._diag.debug('%s instrumentation incomingRequest', component); | ||
instrumentation._diag.debug(`${component} instrumentation incomingRequest`); | ||
if (utils.isIgnored(pathname, instrumentation._getConfig().ignoreIncomingPaths, (e) => instrumentation._diag.error('caught ignoreIncomingPaths error: ', e))) { | ||
@@ -274,2 +278,3 @@ return api_1.context.with(core_1.suppressTracing(api_1.context.active()), () => { | ||
} | ||
instrumentation._headerCapture.server.captureRequestHeaders(span, header => request.headers[header]); | ||
// Wraps end (inspired by: | ||
@@ -289,2 +294,3 @@ // https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/blob/master/src/instrumentations/instrumentation-connect.ts#L75) | ||
const attributes = utils.getIncomingRequestAttributesOnResponse(request, response); | ||
instrumentation._headerCapture.server.captureResponseHeaders(span, header => response.getHeader(header)); | ||
span | ||
@@ -370,3 +376,3 @@ .setAttributes(attributes) | ||
}); | ||
instrumentation._diag.debug('%s instrumentation outgoingRequest', component); | ||
instrumentation._diag.debug(`${component} instrumentation outgoingRequest`); | ||
api_1.context.bind(parentContext, request); | ||
@@ -417,4 +423,18 @@ return instrumentation._traceClientRequest(request, hostname, span); | ||
} | ||
_createHeaderCapture() { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; | ||
const config = this._getConfig(); | ||
return { | ||
client: { | ||
captureRequestHeaders: utils.headerCapture('request', (_c = (_b = (_a = config.headersToSpanAttributes) === null || _a === void 0 ? void 0 : _a.client) === null || _b === void 0 ? void 0 : _b.requestHeaders) !== null && _c !== void 0 ? _c : []), | ||
captureResponseHeaders: utils.headerCapture('response', (_f = (_e = (_d = config.headersToSpanAttributes) === null || _d === void 0 ? void 0 : _d.client) === null || _e === void 0 ? void 0 : _e.responseHeaders) !== null && _f !== void 0 ? _f : []) | ||
}, | ||
server: { | ||
captureRequestHeaders: utils.headerCapture('request', (_j = (_h = (_g = config.headersToSpanAttributes) === null || _g === void 0 ? void 0 : _g.server) === null || _h === void 0 ? void 0 : _h.requestHeaders) !== null && _j !== void 0 ? _j : []), | ||
captureResponseHeaders: utils.headerCapture('response', (_m = (_l = (_k = config.headersToSpanAttributes) === null || _k === void 0 ? void 0 : _k.server) === null || _l === void 0 ? void 0 : _l.responseHeaders) !== null && _m !== void 0 ? _m : []), | ||
} | ||
}; | ||
} | ||
} | ||
exports.HttpInstrumentation = HttpInstrumentation; | ||
//# sourceMappingURL=http.js.map |
@@ -59,2 +59,13 @@ /// <reference types="node" /> | ||
requireParentforIncomingSpans?: boolean; | ||
/** Map the following HTTP headers to span attributes. */ | ||
headersToSpanAttributes?: { | ||
client?: { | ||
requestHeaders?: string[]; | ||
responseHeaders?: string[]; | ||
}; | ||
server?: { | ||
requestHeaders?: string[]; | ||
responseHeaders?: string[]; | ||
}; | ||
}; | ||
} | ||
@@ -61,0 +72,0 @@ export interface Err extends Error { |
@@ -109,2 +109,3 @@ /// <reference types="node" /> | ||
export declare const getIncomingRequestAttributesOnResponse: (request: IncomingMessage, response: ServerResponse) => SpanAttributes; | ||
export declare function headerCapture(type: 'request' | 'response', headers: string[]): (span: Span, getHeader: (key: string) => undefined | string | string[] | number) => void; | ||
//# sourceMappingURL=utils.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getIncomingRequestAttributesOnResponse = exports.getIncomingRequestAttributes = exports.getOutgoingRequestAttributesOnResponse = exports.getAttributesFromHttpKind = exports.getOutgoingRequestAttributes = exports.isValidOptionsType = exports.getRequestInfo = exports.isCompressed = exports.setResponseContentLengthAttribute = exports.setRequestContentLengthAttribute = exports.setSpanWithError = exports.isIgnored = exports.satisfiesPattern = exports.hasExpectHeader = exports.parseResponseStatus = exports.getAbsoluteUrl = void 0; | ||
exports.headerCapture = exports.getIncomingRequestAttributesOnResponse = exports.getIncomingRequestAttributes = exports.getOutgoingRequestAttributesOnResponse = exports.getAttributesFromHttpKind = exports.getOutgoingRequestAttributes = exports.isValidOptionsType = exports.getRequestInfo = exports.isCompressed = exports.setResponseContentLengthAttribute = exports.setRequestContentLengthAttribute = exports.setSpanWithError = exports.isIgnored = exports.satisfiesPattern = exports.hasExpectHeader = exports.parseResponseStatus = exports.getAbsoluteUrl = void 0; | ||
/* | ||
@@ -366,3 +366,2 @@ * Copyright The OpenTelemetry Authors | ||
if (requestUrl) { | ||
attributes[semantic_conventions_1.SemanticAttributes.HTTP_ROUTE] = requestUrl.pathname || '/'; | ||
attributes[semantic_conventions_1.SemanticAttributes.HTTP_TARGET] = requestUrl.pathname || '/'; | ||
@@ -403,2 +402,24 @@ } | ||
exports.getIncomingRequestAttributesOnResponse = getIncomingRequestAttributesOnResponse; | ||
function headerCapture(type, headers) { | ||
const normalizedHeaders = new Map(headers.map(header => [header.toLowerCase(), header.toLowerCase().replace(/-/g, '_')])); | ||
return (span, getHeader) => { | ||
for (const [capturedHeader, normalizedHeader] of normalizedHeaders) { | ||
const value = getHeader(capturedHeader); | ||
if (value === undefined) { | ||
continue; | ||
} | ||
const key = `http.${type}.header.${normalizedHeader}`; | ||
if (typeof value === 'string') { | ||
span.setAttribute(key, [value]); | ||
} | ||
else if (Array.isArray(value)) { | ||
span.setAttribute(key, value); | ||
} | ||
else { | ||
span.setAttribute(key, [value]); | ||
} | ||
} | ||
}; | ||
} | ||
exports.headerCapture = headerCapture; | ||
//# sourceMappingURL=utils.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.25.0"; | ||
export declare const VERSION = "0.26.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,3 +20,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.25.0'; | ||
exports.VERSION = '0.26.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/instrumentation-http", | ||
"version": "0.25.1-alpha.24+a1875b67", | ||
"version": "0.26.0", | ||
"description": "OpenTelemetry http/https automatic instrumentation package.", | ||
@@ -16,6 +16,6 @@ "main": "build/src/index.js", | ||
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", | ||
"version": "node ../../scripts/version-update.js", | ||
"version": "node ../../../scripts/version-update.js", | ||
"watch": "tsc --build --watch", | ||
"precompile": "lerna run version --scope $(npm pkg get name) --include-filtered-dependencies", | ||
"prewatch": "npm run precompile" | ||
"prewatch": "node ../../../scripts/version-update.js" | ||
}, | ||
@@ -48,5 +48,5 @@ "keywords": [ | ||
"@opentelemetry/api": "^1.0.2", | ||
"@opentelemetry/context-async-hooks": "^0.25.0", | ||
"@opentelemetry/sdk-trace-base": "^0.25.0", | ||
"@opentelemetry/sdk-trace-node": "^0.25.0", | ||
"@opentelemetry/context-async-hooks": "1.0.0", | ||
"@opentelemetry/sdk-trace-base": "1.0.0", | ||
"@opentelemetry/sdk-trace-node": "1.0.0", | ||
"@types/got": "9.6.12", | ||
@@ -77,8 +77,8 @@ "@types/mocha": "8.2.3", | ||
"dependencies": { | ||
"@opentelemetry/core": "^0.25.0", | ||
"@opentelemetry/instrumentation": "^0.25.0", | ||
"@opentelemetry/semantic-conventions": "^0.25.0", | ||
"@opentelemetry/core": "1.0.0", | ||
"@opentelemetry/instrumentation": "0.26.0", | ||
"@opentelemetry/semantic-conventions": "1.0.0", | ||
"semver": "^7.3.5" | ||
}, | ||
"gitHead": "a1875b67852cdc1004fee144ce5792f33ad2fcdb" | ||
"gitHead": "0f5a5bc906a2166c30a4344e460b7206c0b20bac" | ||
} |
@@ -60,2 +60,3 @@ # OpenTelemetry HTTP and HTTPS Instrumentation for Node.js | ||
| [`requireParentforIncomingSpans`](https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-instrumentation-http/src/types.ts#L105) | Boolean | Require that is a parent span to create new span for incoming requests. | | ||
| [`headersToSpanAttributes`](https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-instrumentation-http/src/types.ts#L107) | `object` | List of case insensitive HTTP headers to convert to span attributes. Client (outgoing requests, incoming responses) and server (incoming requests, outgoing responses) headers will be converted to span attributes in the form of `http.{request\|response}.header.header_name`, e.g. `http.response.header.content_length` | | ||
@@ -62,0 +63,0 @@ ## Useful links |
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
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
151999
1183
81
0
+ Added@opentelemetry/api-metrics@0.26.0(transitive)
+ Added@opentelemetry/core@1.0.0(transitive)
+ Added@opentelemetry/instrumentation@0.26.0(transitive)
+ Added@opentelemetry/semantic-conventions@1.0.0(transitive)
- Removed@opentelemetry/api-metrics@0.25.0(transitive)
- Removed@opentelemetry/core@0.25.0(transitive)
- Removed@opentelemetry/instrumentation@0.25.0(transitive)
- Removed@opentelemetry/semantic-conventions@0.25.0(transitive)
Updated@opentelemetry/core@1.0.0