Skip to content

Commit

Permalink
Merge branch 'main' into example-react
Browse files Browse the repository at this point in the history
  • Loading branch information
trentm authored Apr 24, 2024
2 parents 771208e + a5bee9f commit 4be193d
Show file tree
Hide file tree
Showing 4 changed files with 319 additions and 324 deletions.
196 changes: 94 additions & 102 deletions plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ registerInstrumentationTesting(new AmqplibInstrumentation());

import * as amqpCallback from 'amqplib/callback_api';
import {
MessagingDestinationKindValues,
SemanticAttributes,
MESSAGINGDESTINATIONKINDVALUES_TOPIC,
SEMATTRS_MESSAGING_DESTINATION,
SEMATTRS_MESSAGING_DESTINATION_KIND,
SEMATTRS_MESSAGING_PROTOCOL,
SEMATTRS_MESSAGING_PROTOCOL_VERSION,
SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY,
SEMATTRS_MESSAGING_SYSTEM,
SEMATTRS_MESSAGING_URL,
SEMATTRS_NET_PEER_NAME,
SEMATTRS_NET_PEER_PORT,
} from '@opentelemetry/semantic-conventions';
import { Baggage, context, propagation, SpanKind } from '@opentelemetry/api';
import { asyncConfirmSend, asyncConsume, shouldTest } from './utils';
Expand Down Expand Up @@ -127,67 +135,63 @@ describe('amqplib instrumentation callback model', () => {

// assert publish span
expect(publishSpan.kind).toEqual(SpanKind.PRODUCER);
expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual(
'rabbitmq'
);
expect(publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual(
''
); // according to spec: "This will be an empty string if the default exchange is used"
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM]
).toEqual('rabbitmq');
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used"
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND]
).toEqual(MessagingDestinationKindValues.TOPIC);
publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]
).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC);
expect(
publishSpan.attributes[
SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY
]
publishSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]
).toEqual(queueName);
expect(publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual(
'AMQP'
);
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL]
).toEqual('AMQP');
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION]
publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION]
).toEqual('0.9.1');
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_URL]
).toEqual(censoredUrl);
expect(
publishSpan.attributes[SemanticAttributes.NET_PEER_NAME]
).toEqual(TEST_RABBITMQ_HOST);
expect(
publishSpan.attributes[SemanticAttributes.NET_PEER_PORT]
).toEqual(TEST_RABBITMQ_PORT);
expect(publishSpan.attributes[SEMATTRS_MESSAGING_URL]).toEqual(
censoredUrl
);
expect(publishSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual(
TEST_RABBITMQ_HOST
);
expect(publishSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual(
TEST_RABBITMQ_PORT
);

// assert consume span
expect(consumeSpan.kind).toEqual(SpanKind.CONSUMER);
expect(consumeSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual(
'rabbitmq'
);
expect(consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual(
''
); // according to spec: "This will be an empty string if the default exchange is used"
expect(
consumeSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM]
).toEqual('rabbitmq');
expect(
consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used"
expect(
consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND]
).toEqual(MessagingDestinationKindValues.TOPIC);
consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]
).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC);
expect(
consumeSpan.attributes[
SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY
]
consumeSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]
).toEqual(queueName);
expect(consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual(
'AMQP'
);
expect(
consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL]
).toEqual('AMQP');
expect(
consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION]
consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION]
).toEqual('0.9.1');
expect(
consumeSpan.attributes[SemanticAttributes.MESSAGING_URL]
).toEqual(censoredUrl);
expect(
consumeSpan.attributes[SemanticAttributes.NET_PEER_NAME]
).toEqual(TEST_RABBITMQ_HOST);
expect(
consumeSpan.attributes[SemanticAttributes.NET_PEER_PORT]
).toEqual(TEST_RABBITMQ_PORT);
expect(consumeSpan.attributes[SEMATTRS_MESSAGING_URL]).toEqual(
censoredUrl
);
expect(consumeSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual(
TEST_RABBITMQ_HOST
);
expect(consumeSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual(
TEST_RABBITMQ_PORT
);

// assert context propagation
expect(consumeSpan.spanContext().traceId).toEqual(
Expand Down Expand Up @@ -301,75 +305,63 @@ describe('amqplib instrumentation callback model', () => {

// assert publish span
expect(publishSpan.kind).toEqual(SpanKind.PRODUCER);
expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual(
'rabbitmq'
);
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM]
).toEqual('rabbitmq');
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]
).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used"
expect(
publishSpan.attributes[
SemanticAttributes.MESSAGING_DESTINATION_KIND
]
).toEqual(MessagingDestinationKindValues.TOPIC);
publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]
).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC);
expect(
publishSpan.attributes[
SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY
]
publishSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]
).toEqual(queueName);
expect(publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual(
'AMQP'
);
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL]
).toEqual('AMQP');
expect(
publishSpan.attributes[
SemanticAttributes.MESSAGING_PROTOCOL_VERSION
]
publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION]
).toEqual('0.9.1');
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_URL]
).toEqual(censoredUrl);
expect(
publishSpan.attributes[SemanticAttributes.NET_PEER_NAME]
).toEqual(TEST_RABBITMQ_HOST);
expect(
publishSpan.attributes[SemanticAttributes.NET_PEER_PORT]
).toEqual(TEST_RABBITMQ_PORT);
expect(publishSpan.attributes[SEMATTRS_MESSAGING_URL]).toEqual(
censoredUrl
);
expect(publishSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual(
TEST_RABBITMQ_HOST
);
expect(publishSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual(
TEST_RABBITMQ_PORT
);

// assert consume span
expect(consumeSpan.kind).toEqual(SpanKind.CONSUMER);
expect(consumeSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual(
'rabbitmq'
);
expect(
consumeSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM]
).toEqual('rabbitmq');
expect(
consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]
).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used"
expect(
consumeSpan.attributes[
SemanticAttributes.MESSAGING_DESTINATION_KIND
]
).toEqual(MessagingDestinationKindValues.TOPIC);
consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]
).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC);
expect(
consumeSpan.attributes[
SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY
]
consumeSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]
).toEqual(queueName);
expect(consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual(
'AMQP'
);
expect(
consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL]
).toEqual('AMQP');
expect(
consumeSpan.attributes[
SemanticAttributes.MESSAGING_PROTOCOL_VERSION
]
consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION]
).toEqual('0.9.1');
expect(
consumeSpan.attributes[SemanticAttributes.MESSAGING_URL]
).toEqual(censoredUrl);
expect(
consumeSpan.attributes[SemanticAttributes.NET_PEER_NAME]
).toEqual(TEST_RABBITMQ_HOST);
expect(
consumeSpan.attributes[SemanticAttributes.NET_PEER_PORT]
).toEqual(TEST_RABBITMQ_PORT);
expect(consumeSpan.attributes[SEMATTRS_MESSAGING_URL]).toEqual(
censoredUrl
);
expect(consumeSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual(
TEST_RABBITMQ_HOST
);
expect(consumeSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual(
TEST_RABBITMQ_PORT
);

// assert context propagation
expect(consumeSpan.spanContext().traceId).toEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ import {

registerInstrumentationTesting(new AmqplibInstrumentation());
import * as amqp from 'amqplib';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
SEMATTRS_MESSAGING_PROTOCOL,
SEMATTRS_MESSAGING_PROTOCOL_VERSION,
SEMATTRS_MESSAGING_SYSTEM,
SEMATTRS_MESSAGING_URL,
SEMATTRS_NET_PEER_NAME,
SEMATTRS_NET_PEER_PORT,
} from '@opentelemetry/semantic-conventions';

describe('amqplib instrumentation connection', () => {
before(function () {
Expand Down Expand Up @@ -60,24 +67,22 @@ describe('amqplib instrumentation connection', () => {
);
const [publishSpan] = getTestSpans();

expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual(
'rabbitmq'
);
expect(publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual(
'AMQP'
);
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM]
).toEqual('rabbitmq');
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL]
).toEqual('AMQP');
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION]
publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION]
).toEqual('0.9.1');
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_URL]
).toBeUndefined(); // no url string if value supplied as object
expect(
publishSpan.attributes[SemanticAttributes.NET_PEER_NAME]
).toEqual(TEST_RABBITMQ_HOST);
expect(
publishSpan.attributes[SemanticAttributes.NET_PEER_PORT]
).toEqual(TEST_RABBITMQ_PORT);
expect(publishSpan.attributes[SEMATTRS_MESSAGING_URL]).toBeUndefined(); // no url string if value supplied as object
expect(publishSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual(
TEST_RABBITMQ_HOST
);
expect(publishSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual(
TEST_RABBITMQ_PORT
);
} finally {
await conn.close();
}
Expand All @@ -99,9 +104,9 @@ describe('amqplib instrumentation connection', () => {
Buffer.from('message created only to test connection attributes')
);
const [publishSpan] = getTestSpans();
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL]
).toEqual('AMQP');
expect(publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual(
'AMQP'
);
} finally {
await conn.close();
}
Expand All @@ -127,9 +132,9 @@ describe('amqplib instrumentation connection', () => {
Buffer.from('message created only to test connection attributes')
);
const [publishSpan] = getTestSpans();
expect(
publishSpan.attributes[SemanticAttributes.NET_PEER_NAME]
).toEqual(TEST_RABBITMQ_HOST);
expect(publishSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual(
TEST_RABBITMQ_HOST
);
} finally {
await conn.close();
}
Expand All @@ -149,24 +154,24 @@ describe('amqplib instrumentation connection', () => {
);
const [publishSpan] = getTestSpans();

expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual(
'rabbitmq'
);
expect(publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual(
'AMQP'
);
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM]
).toEqual('rabbitmq');
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL]
).toEqual('AMQP');
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION]
publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION]
).toEqual('0.9.1');
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_URL]
).toEqual(censoredUrl);
expect(
publishSpan.attributes[SemanticAttributes.NET_PEER_NAME]
).toEqual(TEST_RABBITMQ_HOST);
expect(
publishSpan.attributes[SemanticAttributes.NET_PEER_PORT]
).toEqual(TEST_RABBITMQ_PORT);
expect(publishSpan.attributes[SEMATTRS_MESSAGING_URL]).toEqual(
censoredUrl
);
expect(publishSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual(
TEST_RABBITMQ_HOST
);
expect(publishSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual(
TEST_RABBITMQ_PORT
);
} finally {
await conn.close();
}
Expand Down
Loading

0 comments on commit 4be193d

Please sign in to comment.