Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// It's likely that the refresh token has expired, so
// return null so that the credential implementation will
// initiate the authentication flow again.
logger.info(`IdentityClient: interaction required for client ID: ${clientId}`);
span.setStatus({
code: CanonicalCode.UNAUTHENTICATED,
message: err.message
});
return null;
} else {
logger.warning(
`IdentityClient: failed refreshing token for client ID: ${clientId}: ${err}`
);
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: err.message
});
throw err;
}
} finally {
span.end();
}
}
export function handleInvalidQuery(
this: pgTypes.Client & PgClientExtended,
tracer: Tracer,
originalQuery: typeof pgTypes.Client.prototype.query,
...args: unknown[]
) {
let result;
const span = pgStartSpan(tracer, this, PostgresPlugin.BASE_SPAN_NAME);
try {
result = originalQuery.apply(this, args as never);
span.setStatus({ code: CanonicalCode.OK }); // this will never happen, but set a status anyways
} catch (e) {
span.setStatus({ code: CanonicalCode.UNKNOWN, message: e.message });
throw e;
} finally {
span.end();
}
return result;
}
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]) })
return function internal_send_command_trace(
this: redisTypes.RedisClient & RedisPluginClientTypes,
cmd?: RedisCommand
) {
// New versions of redis (2.4+) use a single options object
// instead of named arguments
if (arguments.length === 1 && typeof cmd === 'object') {
const span = tracer.startSpan(`${RedisPlugin.COMPONENT}-${cmd.command}`, {
kind: SpanKind.CLIENT,
parent: tracer.getCurrentSpan(),
attributes: {
[AttributeNames.COMPONENT]: RedisPlugin.COMPONENT,
[AttributeNames.DB_STATEMENT]: cmd.command,
},
});
// Set attributes for not explicitly typed RedisPluginClientTypes
if (this.options) {
span.setAttributes({
[AttributeNames.PEER_HOSTNAME]: this.options.host,
[AttributeNames.PEER_PORT]: this.options.port,
});
}
if (this.address) {
span.setAttribute(
const callbackFuncIndex = findIndex(args, arg => {
return typeof arg === 'function';
});
if (callbackFuncIndex !== -1) {
args[callbackFuncIndex] = patchedCallback(
span,
args[callbackFuncIndex],
metadata
);
}
}
span.addEvent('sent');
span.setAttributes({
[AttributeNames.GRPC_METHOD]: original.path,
[AttributeNames.GRPC_KIND]: SpanKind.CLIENT,
});
this._setSpanContext(metadata, span.context());
const call = original.apply(self, args);
// if server stream or bidi
if (original.responseStream) {
// Both error and status events can be emitted
// the first one emitted set spanEnded to true
let spanEnded = false;
const endSpan = () => {
if (!spanEnded) {
span.end();
spanEnded = true;
}
};
function pgStartSpan(
tracer: Tracer,
client: pgTypes.Client & PgClientExtended,
name: string
) {
const jdbcString = getJDBCString(client.connectionParameters);
return tracer.startSpan(name, {
kind: SpanKind.CLIENT,
parent: tracer.getCurrentSpan(),
attributes: {
[AttributeNames.COMPONENT]: PostgresPlugin.COMPONENT, // required
[AttributeNames.DB_INSTANCE]: client.connectionParameters.database, // required
[AttributeNames.DB_TYPE]: PostgresPlugin.DB_TYPE, // required
[AttributeNames.PEER_ADDRESS]: jdbcString, // required
[AttributeNames.PEER_HOSTNAME]: client.connectionParameters.host, // required
[AttributeNames.PEER_PORT]: client.connectionParameters.port,
[AttributeNames.DB_USER]: client.connectionParameters.user,
},
});
}
: undefined
);
options = optionsParsed;
if (
Utils.isOpenTelemetryRequest(options) ||
Utils.isIgnored(origin + pathname, plugin._config.ignoreOutgoingUrls)
) {
return original.apply(this, [options, ...args]);
}
const currentSpan = plugin._tracer.getCurrentSpan();
const operationName = `${method} ${pathname}`;
const spanOptions: SpanOptions = {
kind: SpanKind.CLIENT,
parent: currentSpan ? currentSpan : undefined,
};
const span = plugin._startHttpSpan(operationName, spanOptions);
plugin._tracer
.getHttpTextFormat()
.inject(span.context(), Format.HTTP, options.headers);
const request: ClientRequest = plugin._safeExecute(span, () =>
original.apply(this, [options, ...args])
);
plugin._logger.debug('%s plugin outgoingRequest', plugin.moduleName);
plugin._tracer.bind(request);
// Checks if this outgoing request is part of an operation by checking
return function connect(this: PgPoolExtended, callback?: PgPoolCallback) {
const jdbcString = utils.getJDBCString(this.options);
// setup span
const span = plugin._tracer.startSpan(
`${PostgresPoolPlugin.COMPONENT}.connect`,
{
kind: SpanKind.CLIENT,
parent: plugin._tracer.getCurrentSpan() || undefined,
attributes: {
[AttributeNames.COMPONENT]: PostgresPoolPlugin.COMPONENT, // required
[AttributeNames.DB_TYPE]: PostgresPoolPlugin.DB_TYPE, // required
[AttributeNames.DB_INSTANCE]: this.options.database, // required
[AttributeNames.PEER_HOSTNAME]: this.options.host, // required
[AttributeNames.PEER_ADDRESS]: jdbcString, // required
[AttributeNames.PEER_PORT]: this.options.port,
[AttributeNames.DB_USER]: this.options.user,
[AttributeNames.IDLE_TIMEOUT_MILLIS]: this.options
.idleTimeoutMillis,
[AttributeNames.MAX_CLIENT]: this.options.maxClient,
},
}
);
public async sendRequest(request: WebResource): Promise {
if (!request.spanOptions || !request.spanOptions.parent) {
return this._nextPolicy.sendRequest(request);
}
// create a new span
const tracer = getTracer();
const spanOptions: SpanOptions = {
...request.spanOptions,
kind: SpanKind.CLIENT
};
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 response = await this.sendTokenRequest(webResource, expiresOnParser);
logger.info(`IdentityClient: refreshed token for client ID: ${clientId}`);
return response;
} catch (err) {
if (
err.name === AuthenticationErrorName &&
err.errorResponse.error === "interaction_required"
) {
// It's likely that the refresh token has expired, so
// return null so that the credential implementation will
// initiate the authentication flow again.
logger.info(`IdentityClient: interaction required for client ID: ${clientId}`);
span.setStatus({
code: CanonicalCode.UNAUTHENTICATED,
message: err.message
});
return null;
} else {
logger.warning(
`IdentityClient: failed refreshing token for client ID: ${clientId}: ${err}`
);
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: err.message
});
throw err;
}
} finally {
span.end();