@azure/core-rest-pipeline
Advanced tools
Comparing version 1.2.1-alpha.20210816.6 to 1.2.1-alpha.20210819.2
@@ -11,2 +11,4 @@ # Release History | ||
- `tracingPolicy` will no longer propagate tracing errors to the caller, and such errors will be logged instead and the operation does not get interrupted. [PR #16916](https://github.com/Azure/azure-sdk-for-js/pull/16916) | ||
### Other Changes | ||
@@ -13,0 +15,0 @@ |
@@ -7,2 +7,3 @@ // Copyright (c) Microsoft Corporation. | ||
import { getUserAgentValue } from "../util/userAgent"; | ||
import { logger } from "../log"; | ||
const createSpan = createSpanFunction({ | ||
@@ -31,52 +32,83 @@ packagePrefix: "", | ||
} | ||
// create a new span | ||
const tracingOptions = Object.assign(Object.assign({}, request.tracingOptions), { spanOptions: Object.assign(Object.assign({}, request.tracingOptions.spanOptions), { kind: SpanKind.CLIENT }) }); | ||
const url = new URL(request.url); | ||
const path = url.pathname || "/"; | ||
const { span } = createSpan(path, { tracingOptions }); | ||
span.setAttributes({ | ||
"http.method": request.method, | ||
"http.url": request.url, | ||
requestId: request.requestId | ||
}); | ||
if (userAgent) { | ||
span.setAttribute("http.user_agent", userAgent); | ||
const span = tryCreateSpan(request, userAgent); | ||
if (!span) { | ||
return next(request); | ||
} | ||
try { | ||
// set headers | ||
const spanContext = span.spanContext(); | ||
const traceParentHeader = getTraceParentHeader(spanContext); | ||
if (traceParentHeader && isSpanContextValid(spanContext)) { | ||
request.headers.set("traceparent", traceParentHeader); | ||
const traceState = spanContext.traceState && spanContext.traceState.serialize(); | ||
// if tracestate is set, traceparent MUST be set, so only set tracestate after traceparent | ||
if (traceState) { | ||
request.headers.set("tracestate", traceState); | ||
} | ||
} | ||
const response = await next(request); | ||
span.setAttribute("http.status_code", response.status); | ||
const serviceRequestId = response.headers.get("x-ms-request-id"); | ||
if (serviceRequestId) { | ||
span.setAttribute("serviceRequestId", serviceRequestId); | ||
} | ||
span.setStatus({ | ||
code: SpanStatusCode.OK | ||
}); | ||
tryProcessResponse(span, response); | ||
return response; | ||
} | ||
catch (err) { | ||
span.setStatus({ | ||
code: SpanStatusCode.ERROR, | ||
message: err.message | ||
}); | ||
span.setAttribute("http.status_code", err.statusCode); | ||
tryProcessError(span, err); | ||
throw err; | ||
} | ||
finally { | ||
span.end(); | ||
} | ||
} | ||
}; | ||
} | ||
function tryCreateSpan(request, userAgent) { | ||
var _a; | ||
try { | ||
// create a new span | ||
const tracingOptions = Object.assign(Object.assign({}, request.tracingOptions), { spanOptions: Object.assign(Object.assign({}, (_a = request.tracingOptions) === null || _a === void 0 ? void 0 : _a.spanOptions), { kind: SpanKind.CLIENT }) }); | ||
const url = new URL(request.url); | ||
const path = url.pathname || "/"; | ||
const { span } = createSpan(path, { tracingOptions }); | ||
span.setAttributes({ | ||
"http.method": request.method, | ||
"http.url": request.url, | ||
requestId: request.requestId | ||
}); | ||
if (userAgent) { | ||
span.setAttribute("http.user_agent", userAgent); | ||
} | ||
// set headers | ||
const spanContext = span.spanContext(); | ||
const traceParentHeader = getTraceParentHeader(spanContext); | ||
if (traceParentHeader && isSpanContextValid(spanContext)) { | ||
request.headers.set("traceparent", traceParentHeader); | ||
const traceState = spanContext.traceState && spanContext.traceState.serialize(); | ||
// if tracestate is set, traceparent MUST be set, so only set tracestate after traceparent | ||
if (traceState) { | ||
request.headers.set("tracestate", traceState); | ||
} | ||
} | ||
return span; | ||
} | ||
catch (error) { | ||
logger.warning(`Skipping creating a tracing span due to an error: ${error.message}`); | ||
return undefined; | ||
} | ||
} | ||
function tryProcessError(span, err) { | ||
try { | ||
span.setStatus({ | ||
code: SpanStatusCode.ERROR, | ||
message: err.message | ||
}); | ||
if (err.statusCode) { | ||
span.setAttribute("http.status_code", err.statusCode); | ||
} | ||
span.end(); | ||
} | ||
catch (error) { | ||
logger.warning(`Skipping tracing span processing due to an error: ${error.message}`); | ||
} | ||
} | ||
function tryProcessResponse(span, response) { | ||
try { | ||
span.setAttribute("http.status_code", response.status); | ||
const serviceRequestId = response.headers.get("x-ms-request-id"); | ||
if (serviceRequestId) { | ||
span.setAttribute("serviceRequestId", serviceRequestId); | ||
} | ||
span.setStatus({ | ||
code: SpanStatusCode.OK | ||
}); | ||
span.end(); | ||
} | ||
catch (error) { | ||
logger.warning(`Skipping tracing span processing due to an error: ${error.message}`); | ||
} | ||
} | ||
//# sourceMappingURL=tracingPolicy.js.map |
{ | ||
"name": "@azure/core-rest-pipeline", | ||
"version": "1.2.1-alpha.20210816.6", | ||
"version": "1.2.1-alpha.20210819.2", | ||
"description": "Isomorphic client library for making HTTP requests in node.js and browser.", | ||
@@ -5,0 +5,0 @@ "sdk-type": "client", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
569366
6050