@opencensus/instrumentation-http
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -18,3 +18,4 @@ /** | ||
import { BasePlugin, Func, SpanKind, TagMap } from '@opencensus/core'; | ||
import { ClientRequest, IncomingMessage, request } from 'http'; | ||
import { ClientRequest, IncomingMessage, request, RequestOptions } from 'http'; | ||
import * as url from 'url'; | ||
import { IgnoreMatcher } from './types'; | ||
@@ -80,4 +81,9 @@ export declare type HttpGetCallback = (res: IncomingMessage) => void; | ||
static recordStats(kind: SpanKind, tags: TagMap, ms: number): void; | ||
/** | ||
* Returns whether the Expect header is on the given options object. | ||
* @param options Options for http.request. | ||
*/ | ||
hasExpectHeader(options: RequestOptions | url.URL): boolean; | ||
} | ||
declare const plugin: HttpPlugin; | ||
export { plugin }; |
@@ -31,2 +31,3 @@ "use strict"; | ||
}; | ||
const TAG_VALUE_MAX_LENGTH = 255; | ||
/** Http instrumentation plugin for Opencensus */ | ||
@@ -178,3 +179,6 @@ class HttpPlugin extends core_1.BasePlugin { | ||
rootSpan.addAttribute(HttpPlugin.ATTRIBUTE_HTTP_ROUTE, requestUrl.path || ''); | ||
tags.set(stats.HTTP_SERVER_ROUTE, { value: requestUrl.path || '' }, UNLIMITED_PROPAGATION_MD); | ||
tags.set(stats.HTTP_SERVER_ROUTE, { | ||
value: (requestUrl.path || | ||
'').substring(0, TAG_VALUE_MAX_LENGTH) | ||
}, UNLIMITED_PROPAGATION_MD); | ||
} | ||
@@ -256,3 +260,3 @@ if (userAgent) { | ||
plugin.logger.debug('outgoingRequest starting a child span'); | ||
const span = plugin.tracer.startChildSpan(traceOptions.name, traceOptions.kind); | ||
const span = plugin.tracer.startChildSpan({ name: traceOptions.name, kind: traceOptions.kind }); | ||
return (plugin.getMakeRequestTraceFunction(request, options, plugin))(span); | ||
@@ -279,3 +283,12 @@ } | ||
setHeader(name, value) { | ||
request.setHeader(name, value); | ||
// If outgoing request headers contain the "Expect" header, the | ||
// returned ClientRequest will throw an error if any new headers are | ||
// added. We need to set the header directly in the headers object | ||
// which has been cloned earlier. | ||
if (plugin.hasExpectHeader(options) && options.headers) { | ||
options.headers[name] = value; | ||
} | ||
else { | ||
request.setHeader(name, value); | ||
} | ||
} | ||
@@ -285,2 +298,10 @@ }; | ||
if (propagation) { | ||
// If outgoing request headers contain the "Expect" header, the returned | ||
// ClientRequest will throw an error if any new headers are added. | ||
// So we need to clone the options object to be able to inject new | ||
// header. | ||
if (plugin.hasExpectHeader(options)) { | ||
options = Object.assign({}, options); | ||
options.headers = Object.assign({}, options.headers); | ||
} | ||
propagation.inject(setter, span.spanContext); | ||
@@ -389,2 +410,10 @@ } | ||
} | ||
/** | ||
* Returns whether the Expect header is on the given options object. | ||
* @param options Options for http.request. | ||
*/ | ||
hasExpectHeader(options) { | ||
return !!(options.headers && | ||
options.headers.Expect); | ||
} | ||
} | ||
@@ -391,0 +420,0 @@ /** |
{ | ||
"name": "@opencensus/instrumentation-http", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "Opencensus http automatic instrumentation package.", | ||
@@ -59,5 +59,5 @@ "main": "build/src/index.js", | ||
"gts": "^0.9.0", | ||
"mocha": "^6.0.0", | ||
"mocha": "^6.1.0", | ||
"nock": "^10.0.0", | ||
"nyc": "^13.0.0", | ||
"nyc": "^14.0.0", | ||
"rimraf": "^2.6.2", | ||
@@ -69,3 +69,3 @@ "ts-mocha": "^6.0.0", | ||
"dependencies": { | ||
"@opencensus/core": "^0.0.11", | ||
"@opencensus/core": "^0.0.12", | ||
"semver": "^6.0.0", | ||
@@ -72,0 +72,0 @@ "shimmer": "^1.2.0" |
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
55420
892
+ Added@opencensus/core@0.0.12(transitive)
- Removed@opencensus/core@0.0.11(transitive)
Updated@opencensus/core@^0.0.12