Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function instrumentEventData(eventData: EventData, span: Span): EventData {
if (eventData.properties && eventData.properties[TRACEPARENT_PROPERTY]) {
return eventData;
}
// create a copy so the original isn't modified
eventData = { ...eventData, properties: { ...eventData.properties } };
const traceParent = getTraceParentHeader(span.context());
if (traceParent) {
eventData.properties![TRACEPARENT_PROPERTY] = traceParent;
}
return eventData;
}
const path = URLBuilder.parse(request.url).getPath() || "/";
const span = tracer.startSpan(path, spanOptions);
span.setAttributes({
"http.method": request.method,
"http.url": request.url,
requestId: request.requestId
});
if (this.userAgent) {
span.setAttribute("http.user_agent", this.userAgent);
}
try {
// set headers
const spanContext = span.context();
const traceParentHeader = getTraceParentHeader(spanContext);
if (traceParentHeader) {
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 this._nextPolicy.sendRequest(request);
span.setAttribute("http.status_code", response.status);
const serviceRequestId = response.headers.get("x-ms-request-id");
if (serviceRequestId) {
span.setAttribute("serviceRequestId", serviceRequestId);
}
span.end();