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();
private createSpan(methodName: string, requestOptions: RequestOptionsBase = {}): Span {
const tracer = getTracer();
return tracer.startSpan(methodName, requestOptions && requestOptions.spanOptions);
}
private createSpan(options: T, operationName: keyof TClient) {
const span = getTracer().startSpan(`${this.baseOperationName}.${operationName}`, {
...options.spanOptions,
kind: SpanKind.INTERNAL
});
let newOptions = options;
if (span.isRecording()) {
newOptions = Spanner.addParentToOptions(options, span);
}
return { span, newOptions };
}
export function createSpan(
operationName: string,
tracingOptions: OperationTracingOptions = {}
): { span: Span; spanOptions: SpanOptions } {
const tracer = getTracer();
const spanOptions: SpanOptions = {
...tracingOptions.spanOptions,
kind: SpanKind.INTERNAL
};
const span = tracer.startSpan(`Azure.Storage.DataLake.${operationName}`, spanOptions);
let newOptions = tracingOptions.spanOptions || {};
if (span.isRecording()) {
newOptions = {
...tracingOptions,
parent: span
};
}
return {
export function createMessageSpan(parentSpan?: Span | SpanContext): Span {
const tracer = getTracer();
const span = tracer.startSpan("Azure.EventHubs.message", {
kind: SpanKind.PRODUCER,
parent: parentSpan
});
return span;
}
): Span {
const links: Link[] = [];
for (const receivedEvent of receivedEvents) {
const spanContext = extractSpanContextFromEventData(receivedEvent);
if (spanContext == null) {
continue;
}
links.push({
spanContext
});
}
const span = getTracer().startSpan("Azure.EventHubs.process", {
kind: SpanKind.CONSUMER,
links,
parent: getParentSpan(tracingOptions)
});
span.setAttributes({
component: "eventhubs",
"message_bus.destination": eventHubProperties.eventHubName,
"peer.address": eventHubProperties.endpoint
});
return span;
}
private _createSendSpan(
parentSpan?: Span | SpanContext,
spanContextsToLink: SpanContext[] = []
): Span {
const links: Link[] = spanContextsToLink.map((spanContext) => {
return {
spanContext
};
});
const tracer = getTracer();
const span = tracer.startSpan("Azure.EventHubs.send", {
kind: SpanKind.CLIENT,
parent: parentSpan,
links
});
span.setAttribute("message_bus.destination", this._eventHubName);
span.setAttribute("peer.address", this._endpoint);
return span;
}
export function createSpan(
operationName: string,
tracingOptions: OperationTracingOptions = {}
): { span: Span; spanOptions: SpanOptions } {
const tracer = getTracer();
const spanOptions: SpanOptions = {
...tracingOptions.spanOptions,
kind: SpanKind.INTERNAL
};
const span = tracer.startSpan(`Azure.Storage.Blob.${operationName}`, spanOptions);
let newOptions = tracingOptions.spanOptions || {};
if (span.isRecording()) {
newOptions = {
...tracingOptions,
parent: span
};
}
return {
private createSpan(methodName: string, requestOptions?: RequestOptionsBase): Span {
const tracer = getTracer();
return tracer.startSpan(methodName, requestOptions && requestOptions.spanOptions);
}