Skip to content

Commit

Permalink
Updating tests to correct Semantic attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
McSick committed May 29, 2024
1 parent b6470a3 commit 80dbd23
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 232 deletions.
184 changes: 84 additions & 100 deletions plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,67 +459,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
);

// new trace should be created
expect(consumeSpan.spanContext().traceId).not.toEqual(
Expand Down Expand Up @@ -591,75 +587,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
);

// new trace should be created
expect(consumeSpan.spanContext().traceId).not.toEqual(
Expand Down
Loading

0 comments on commit 80dbd23

Please sign in to comment.