Skip to content

Commit

Permalink
Merge branch 'main' into abhi-types-amqplib
Browse files Browse the repository at this point in the history
  • Loading branch information
blumamir authored Feb 7, 2023
2 parents 10bf81d + ad92673 commit 8353d80
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugins/node/instrumentation-amqplib/src/amqplib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export class AmqplibInstrumentation extends InstrumentationBase {
msg[MESSAGE_STORED_SPAN] = span;
}

context.with(trace.setSpan(context.active(), span), () => {
context.with(trace.setSpan(parentContext, span), () => {
onMessage.call(this, msg);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,35 @@ import {
MessagingDestinationKindValues,
SemanticAttributes,
} from '@opentelemetry/semantic-conventions';
import { context, SpanKind } from '@opentelemetry/api';
import { Baggage, context, propagation, SpanKind } from '@opentelemetry/api';
import { asyncConfirmSend, asyncConsume, shouldTest } from './utils';
import {
censoredUrl,
rabbitMqUrl,
TEST_RABBITMQ_HOST,
TEST_RABBITMQ_PORT,
} from './config';
import {
CompositePropagator,
W3CBaggagePropagator,
W3CTraceContextPropagator,
} from '@opentelemetry/core';

const msgPayload = 'payload from test';
const queueName = 'queue-name-from-unittest';

describe('amqplib instrumentation callback model', () => {
let conn: amqpCallback.Connection;
before(() => {
propagation.setGlobalPropagator(
new CompositePropagator({
propagators: [
new W3CBaggagePropagator(),
new W3CTraceContextPropagator(),
],
})
);
});
before(function (done) {
if (!shouldTest) {
this.skip();
Expand Down Expand Up @@ -186,6 +201,35 @@ describe('amqplib instrumentation callback model', () => {
});
});

it('baggage is available while consuming', done => {
const baggageContext = propagation.setBaggage(
context.active(),
propagation.createBaggage({
key1: { value: 'value1' },
})
);
context.with(baggageContext, () => {
channel.sendToQueue(queueName, Buffer.from(msgPayload));
let extractedBaggage: Baggage | undefined;
asyncConsume(
channel,
queueName,
[
msg => {
extractedBaggage = propagation.getActiveBaggage();
},
],
{
noAck: true,
}
).then(() => {
expect(extractedBaggage).toBeDefined();
expect(extractedBaggage!.getEntry('key1')).toBeDefined();
done();
});
});
});

it('end span with ack sync', done => {
channel.sendToQueue(queueName, Buffer.from(msgPayload));

Expand Down

0 comments on commit 8353d80

Please sign in to comment.