Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const traceIdLow = span.spanContext.traceId.slice(16);
const parentSpan = span.parentSpanId
? Utils.encodeInt64(span.parentSpanId)
: ThriftUtils.emptyBuffer;
const tags = Object.keys(span.attributes).map(
(name): Tag => ({ key: name, value: toTagValue(span.attributes[name]) })
);
tags.push({ key: 'status.code', value: span.status.code });
tags.push({ key: 'status.name', value: CanonicalCode[span.status.code] });
if (span.status.message) {
tags.push({ key: 'status.message', value: span.status.message });
}
// Ensure that if Status.Code is not OK, that we set the "error" tag on the
// Jaeger span.
if (span.status.code !== CanonicalCode.OK) {
tags.push({ key: 'error', value: true });
}
if (span.kind !== undefined) {
tags.push({ key: 'span.kind', value: SpanKind[span.kind] });
}
const spanTags: ThriftTag[] = ThriftUtils.getThriftTags(tags);
const logs = span.events.map(
(event): Log => {
const fields: Tag[] = [{ key: 'message.id', value: event.name }];
const attrs = event.attributes;
if (attrs) {
Object.keys(attrs).forEach(attr =>
fields.push({ key: attr, value: toTagValue(attrs[attr]) })
const endSpan = (span: Span, err?: Error | null) => {
if (err) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: err.message,
});
} else {
span.setStatus({ code: CanonicalCode.OK });
}
span.end();
};
return function patchedEnd(this: {}, ...args: unknown[]) {
const error = args[0];
if (error instanceof Error) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: error.message,
});
} else {
span.setStatus({
code: CanonicalCode.OK,
});
}
span.end();
return resultHandler.apply(this, args);
};
}
eventData[i] = instrumentEventData(eventData[i], messageSpan);
messageSpan.end();
}
}
} else if (isEventDataBatch(eventData)) {
spanContextsToLink = eventData._messageSpanContexts;
}
const sendSpan = this._createSendSpan(getParentSpan(options), spanContextsToLink);
try {
const result = await this._eventHubSender!.send(eventData, {
...this._senderOptions,
...options
});
sendSpan.setStatus({ code: CanonicalCode.OK });
return result;
} catch (err) {
sendSpan.setStatus({
code: CanonicalCode.UNKNOWN,
message: err.message
});
throw err;
} finally {
sendSpan.end();
}
}
export const parseResponseStatus = (
statusCode: number
): Omit => {
if (statusCode < 200 || statusCode > 504) {
return { code: CanonicalCode.UNKNOWN };
} else if (statusCode >= 200 && statusCode < 400) {
return { code: CanonicalCode.OK };
} else {
switch (statusCode) {
case 400:
return { code: CanonicalCode.INVALID_ARGUMENT };
case 504:
return { code: CanonicalCode.DEADLINE_EXCEEDED };
case 404:
return { code: CanonicalCode.NOT_FOUND };
case 403:
return { code: CanonicalCode.PERMISSION_DENIED };
case 401:
return { code: CanonicalCode.UNAUTHENTICATED };
case 429:
return { code: CanonicalCode.RESOURCE_EXHAUSTED };
case 501:
return { code: CanonicalCode.UNIMPLEMENTED };
export async function trace(fn: () => Promise, span: Span): Promise {
try {
await fn();
span.setStatus({ code: CanonicalCode.OK });
} catch (err) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: err.message
});
throw err;
} finally {
span.end();
}
}
return new Promise((resolve, _) => {
span.setStatus({ code: CanonicalCode.OK });
span.end();
resolve(result);
});
})
const wrappedFn = (err: grpcTypes.ServiceError, res: any) => {
if (err) {
if (err.code) {
span.setStatus(_grpcStatusCodeToSpanStatus(err.code));
span.setAttribute(
AttributeNames.GRPC_STATUS_CODE,
err.code.toString()
);
}
span.setAttributes({
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
});
} else {
span.setStatus({ code: CanonicalCode.OK });
span.setAttribute(
AttributeNames.GRPC_STATUS_CODE,
plugin._moduleExports.status.OK.toString()
);
}
span.end();
callback(err, res);
};
return plugin._tracer.bind(wrappedFn);
return function patchedCallback(
this: pgTypes.Client & PgClientExtended,
err: Error,
res: object
) {
if (err) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: err.message,
});
} else if (res) {
span.setStatus({ code: CanonicalCode.OK });
}
span.end();
cb.call(this, err, res);
};
}