Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(instr-amqpllib): use semconv strings in test files #2113

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading