Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async execute(message: IMessage): Promise {
const { properties } = message;
console.log(`Executing task: ${properties.activityId} with the class HelloWorldTaskV2`);
console.log(`${properties.bpmnProcessId}::${properties.processInstanceId} Servus!`);
console.log(`version: ${properties.workflowDefinitionVersion}`);
const response = await axios.get('https://jsonplaceholder.typicode.com/todos/1');
const tracer = tracerService.getTracer();
const span = tracer.startChildSpan({ name: 'customSpan', kind: SpanKind.CLIENT });
console.log();
console.log('data:');
console.log(response.data);
// put your business logic here
span.end();
return Promise.resolve(message);
}
}
}
}
const request: httpModule.ClientRequest =
original.apply(this, arguments)
if (plugin.isIgnored(origin + pathname, request, plugin.options.ignoreOutgoingUrls)) {
return request
}
plugin.tracer.wrapEmitter(request)
plugin.logger.debug('%s plugin outgoingRequest', plugin.moduleName)
const traceOptions = {
name: `${kind.toLowerCase()}-${(method || 'GET').toLowerCase()}`,
kind: SpanKind.CLIENT
}
// Checks if this outgoing request is part of an operation by checking
// if there is a current root span, if so, we create a child span. In
// case there is no root span, this means that the outgoing request is
// the first operation, therefore we create a root span.
if (!plugin.tracer.currentRootSpan) {
plugin.logger.debug('outgoingRequest starting a root span')
return plugin.tracer.startRootSpan(
traceOptions,
plugin.getMakeRequestTraceFunction(request, options, plugin))
} else {
plugin.logger.debug('outgoingRequest starting a child span')
const span = plugin.tracer.startChildSpan(
traceOptions.name, traceOptions.kind)
return (plugin.getMakeRequestTraceFunction(request, options, plugin))(
span)
translateSpan(span: Span): TranslatedSpan {
const spanTranslated: TranslatedSpan = {
traceId: span.traceId,
name: span.name,
id: span.id,
// Zipkin API for span kind only accept
// (CLIENT|SERVER|PRODUCER|CONSUMER)
kind: span.kind === SpanKind.CLIENT ? 'CLIENT' : 'SERVER',
timestamp: span.startTime.getTime() * MICROS_PER_MILLI,
duration: Math.round(span.duration * MICROS_PER_MILLI),
debug: true,
shared: !span.parentSpanId,
localEndpoint: { serviceName: this.serviceName },
tags: this.createTags(span.attributes, span.status),
annotations: this.createAnnotations(span.annotations, span.messageEvents),
};
if (span.parentSpanId) {
spanTranslated.parentId = span.parentSpanId;
}
return spanTranslated;
}
tracer.startRootSpan({ name: 'removeRootSpan' }, async (rootSpan: RootSpan) => {
await client.del('test')
assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0)
rootSpan.end()
assertSpan(rootSpanVerifier, `redis-del`, SpanKind.CLIENT,
(span) => {
return span.attributes.arguments === undefined
})
done()
})
})
client.query(q, (err, result) => {
assert.strictEqual(result[0]['1'], 1)
assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0)
rootSpan.end()
assert.ifError(err)
assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 1)
assert.strictEqual(rootSpanVerifier.endedRootSpans[0].spans.length, 1)
assert.strictEqual(rootSpanVerifier.endedRootSpans[0].spans[0].attributes.sql, q)
assertSpan(rootSpanVerifier, 'mysql-query', SpanKind.CLIENT)
done()
})
})
conn.query(q, (err, result) => {
assert.strictEqual(result[0]['1'], 1)
assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0)
rootSpan.end()
assert.ifError(err)
assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 1)
assert.strictEqual(rootSpanVerifier.endedRootSpans[0].spans.length, 1)
assert.strictEqual(rootSpanVerifier.endedRootSpans[0].spans[0].attributes.sql, q)
assertSpan(rootSpanVerifier, 'mysql-query', SpanKind.CLIENT)
done()
})
})
client.query(q, (err, result) => {
assert.strictEqual(result.rows[0].value, 1)
assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0)
rootSpan.end()
assert.ifError(err)
assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 1)
assert.strictEqual(rootSpanVerifier.endedRootSpans[0].spans.length, 1)
assert.strictEqual(rootSpanVerifier.endedRootSpans[0].spans[0].attributes.query, q)
assertSpan(rootSpanVerifier, 'pg-query', SpanKind.CLIENT)
done()
})
})
static recordStats(kind: SpanKind, tags: TagMap, ms: number) {
if (!plugin.stats) return;
try {
const measureList = [];
switch (kind) {
case SpanKind.CLIENT:
measureList.push({
measure: stats.HTTP_CLIENT_ROUNDTRIP_LATENCY,
value: ms,
});
break;
case SpanKind.SERVER:
measureList.push({ measure: stats.HTTP_SERVER_LATENCY, value: ms });
break;
default:
break;
}
plugin.stats.record(measureList, tags);
} catch (ignore) {}
}
const resultHandler = typeof options === 'function' ? options : callback
if (plugin.tracer.currentRootSpan && typeof resultHandler === 'function') {
let type: string
if (command.createIndexes) {
type = 'createIndexes'
} else if (command.findandmodify) {
type = 'findAndModify'
} else if (command.ismaster) {
type = 'isMaster'
} else if (command.count) {
type = 'count'
} else {
type = 'command'
}
const span = plugin.tracer.startChildSpan(label, SpanKind.CLIENT)
if (span === null) return original.apply(this, arguments)
span.addAttribute('database', ns)
span.addAttribute('type', type)
if (plugin.options.detailedCommands === true) {
span.addAttribute('command', JSON.stringify(command))
}
if (typeof options === 'function') {
return original.call(this, ns, command, plugin.patchEnd(span, options))
} else {
return original.call(this, ns, command,
options, plugin.patchEnd(span, callback))
}
}
return function (...args: any[]) {
const span = plugin.tracer.startChildSpan('mysql-query', SpanKind.CLIENT)
if (span === null) return original.apply(this, arguments)
const query = original.apply(this, arguments)
span.addAttribute('sql', query.sql)
if (plugin.options.detailedCommands === true && query.values) {
span.addAttribute('values', query.values)
}
if (typeof query._callback === 'function') {
query._callback = plugin.patchEnd(span, query._callback)
} else {
query.on('end', function () {
span.end()
})
}
return query
}