-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58fbf1e
commit 7e0c156
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/expect-opentelemetry/src/matchers/service/to-send-redis-command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; | ||
import { opentelemetry } from '@traceloop/otel-proto'; | ||
import { RedisCommand, Service } from '../../resources'; | ||
|
||
export function toSendRedisCommand(service: Service): RedisCommand { | ||
const { name: serviceName, spans } = service; | ||
|
||
const filteredSpans = spans.filter((span) => { | ||
return ( | ||
span.kind === | ||
opentelemetry.proto.trace.v1.Span.SpanKind.SPAN_KIND_CLIENT && | ||
span.attributes?.find( | ||
(attribute: opentelemetry.proto.common.v1.IKeyValue) => { | ||
return ( | ||
attribute.key === SemanticAttributes.DB_SYSTEM && | ||
attribute.value?.stringValue === 'redis' | ||
); | ||
}, | ||
) | ||
); | ||
}); | ||
|
||
if (filteredSpans.length === 0) { | ||
throw new Error(`No redis command from ${serviceName} found`); | ||
} | ||
|
||
return new RedisCommand(filteredSpans, serviceName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/expect-opentelemetry/src/resources/redis-command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; | ||
import { opentelemetry } from '@traceloop/otel-proto'; | ||
import { | ||
CompareOptions, | ||
filterByAttributeStringValue, | ||
} from '../matchers/utils'; | ||
|
||
export class RedisCommand { | ||
constructor( | ||
readonly spans: opentelemetry.proto.trace.v1.ISpan[], | ||
private readonly serviceName: string, | ||
) {} | ||
|
||
withDatabaseName(name: string | RegExp, options: CompareOptions) { | ||
const filteredSpans = filterByAttributeStringValue( | ||
this.spans, | ||
SemanticAttributes.DB_NAME, | ||
name, | ||
options, | ||
); | ||
|
||
if (filteredSpans.length === 0) { | ||
throw new Error( | ||
`No redis command from service ${this.serviceName} to database ${name} found`, | ||
); | ||
} | ||
|
||
return new RedisCommand(filteredSpans, this.serviceName); | ||
} | ||
|
||
withStatement(statement: string | RegExp, options: CompareOptions) { | ||
const filteredSpans = filterByAttributeStringValue( | ||
this.spans, | ||
SemanticAttributes.DB_STATEMENT, | ||
statement, | ||
options, | ||
); | ||
|
||
if (filteredSpans.length === 0) { | ||
throw new Error( | ||
`No redis command with statement ${statement} from service ${this.serviceName} found`, | ||
); | ||
} | ||
|
||
return new RedisCommand(filteredSpans, this.serviceName); | ||
} | ||
} |