Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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();
if (
currentSpan === undefined ||
typeof resultHandler !== 'function' ||
typeof commands !== 'object'
) {
return original.apply(this, (arguments as unknown) as unknown[]);
}
const command = commands instanceof Array ? commands[0] : commands;
const commandType = plugin._getCommandType(command);
const type =
commandType === MongodbCommandType.UNKNOWN
? operationName
: commandType;
const span = plugin._tracer.startSpan(`mongodb.${type}`, {
parent: currentSpan,
kind: SpanKind.CLIENT,
});
plugin._populateAttributes(
span,
ns,
command,
this as MongoInternalTopology
);
return original.call(
this,
ns,
commands,
plugin._patchEnd(span, resultHandler)
);
};
};
private _startDnsSpan(name: string, options: Omit) {
return this._tracer
.startSpan(name, { ...options, kind: SpanKind.CLIENT })
.setAttribute(AttributeNames.COMPONENT, this.component);
}
return function clientMethodTrace(this: grpcTypes.Client) {
const name = `grpc.${original.path.replace('/', '')}`;
const args = Array.prototype.slice.call(arguments);
const span = plugin._tracer
.startSpan(name, {
kind: SpanKind.CLIENT,
parent: plugin._tracer.getCurrentSpan(),
})
.setAttribute(AttributeNames.COMPONENT, GrpcPlugin.component);
return plugin._makeGrpcClientRemoteCall(
original,
args,
this,
plugin
)(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;
}