Skip to content

Commit

Permalink
chore: use MessagingOperationValues constants (open-telemetry#914)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Feb 22, 2022
1 parent 0a557e8 commit 40608b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
} from '../types';
import {
MessagingDestinationKindValues,
MessagingOperationValues,
SemanticAttributes,
} from '@opentelemetry/semantic-conventions';
import {
Expand Down Expand Up @@ -63,7 +64,8 @@ export class SqsServiceExtension implements ServiceExtension {
isIncoming = true;
spanKind = SpanKind.CONSUMER;
spanName = `${queueName} receive`;
spanAttributes[SemanticAttributes.MESSAGING_OPERATION] = 'receive';
spanAttributes[SemanticAttributes.MESSAGING_OPERATION] =
MessagingOperationValues.RECEIVE;

request.commandInput.MessageAttributeNames = (
request.commandInput.MessageAttributeNames ?? []
Expand Down Expand Up @@ -145,7 +147,8 @@ export class SqsServiceExtension implements ServiceExtension {
MessagingDestinationKindValues.QUEUE,
[SemanticAttributes.MESSAGING_MESSAGE_ID]: message.MessageId,
[SemanticAttributes.MESSAGING_URL]: queueUrl,
[SemanticAttributes.MESSAGING_OPERATION]: 'process',
[SemanticAttributes.MESSAGING_OPERATION]:
MessagingOperationValues.PROCESS,
},
}),
processHook: (span: Span, message: SQS.Message) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ const instrumentation = registerInstrumentationTesting(
import * as AWS from 'aws-sdk';
import { AWSError } from 'aws-sdk';

import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
MessagingOperationValues,
SemanticAttributes,
} from '@opentelemetry/semantic-conventions';
import {
context,
SpanKind,
Expand Down Expand Up @@ -171,12 +174,16 @@ describe('SQS', () => {
numChildPerProcessSpan: number
) => {
const awsReceiveSpan = spans.filter(
s => s.attributes[SemanticAttributes.MESSAGING_OPERATION] === 'receive'
s =>
s.attributes[SemanticAttributes.MESSAGING_OPERATION] ===
MessagingOperationValues.RECEIVE
);
expect(awsReceiveSpan.length).toBe(1);

const processSpans = spans.filter(
s => s.attributes[SemanticAttributes.MESSAGING_OPERATION] === 'process'
s =>
s.attributes[SemanticAttributes.MESSAGING_OPERATION] ===
MessagingOperationValues.PROCESS
);
expect(processSpans.length).toBe(2);
expect(processSpans[0].parentSpanId).toStrictEqual(
Expand Down Expand Up @@ -380,7 +387,9 @@ describe('SQS', () => {
);

const processSpans = getTestSpans().filter(
s => s.attributes[SemanticAttributes.MESSAGING_OPERATION] === 'process'
s =>
s.attributes[SemanticAttributes.MESSAGING_OPERATION] ===
MessagingOperationValues.PROCESS
);
expect(processSpans.length).toBe(2);
expect(
Expand All @@ -402,7 +411,9 @@ describe('SQS', () => {
message => 'some mapping to create child process spans'
);
const processSpans = getTestSpans().filter(
s => s.attributes[SemanticAttributes.MESSAGING_OPERATION] === 'process'
s =>
s.attributes[SemanticAttributes.MESSAGING_OPERATION] ===
MessagingOperationValues.PROCESS
);
expect(processSpans.length).toBe(2);
});
Expand All @@ -429,7 +440,9 @@ describe('SQS', () => {
);

const processSpans = getTestSpans().filter(
s => s.attributes[SemanticAttributes.MESSAGING_OPERATION] === 'process'
s =>
s.attributes[SemanticAttributes.MESSAGING_OPERATION] ===
MessagingOperationValues.PROCESS
);
expect(processSpans.length).toBe(2);
expect(processSpans[0].status.code).toStrictEqual(SpanStatusCode.UNSET);
Expand Down

0 comments on commit 40608b1

Please sign in to comment.