forked from traceloop/jest-opentelemetry
-
Notifications
You must be signed in to change notification settings - Fork 0
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
c05bda4
commit e8c3193
Showing
7 changed files
with
115 additions
and
56 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
packages/expect-opentelemetry/src/matchers/service/http-request.test.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,29 @@ | ||
import { jest, describe, it } from '@jest/globals'; | ||
import { expectTrace } from '../..'; | ||
import { TraceLoop } from '../../trace-loop'; | ||
|
||
jest.setTimeout(30000); | ||
|
||
describe('http request matchers', () => { | ||
describe('when orders-service makes an http call to emails-service', () => { | ||
let traceloop: TraceLoop; | ||
beforeAll(async () => { | ||
traceloop = new TraceLoop(); | ||
|
||
await traceloop.axiosInstance.post('http://localhost:3000/orders/create'); | ||
await traceloop.fetchTraces(); | ||
}); | ||
|
||
it('should contain outbound http call from orders-service', async () => { | ||
expectTrace( | ||
traceloop.serviceByName('orders-service'), | ||
).toSendHttpRequest(); | ||
}); | ||
|
||
it('should contain inbound http call to emails-service', async () => { | ||
expectTrace( | ||
traceloop.serviceByName('emails-service'), | ||
).toReceiveHttpRequest(); | ||
}); | ||
}); | ||
}); |
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
21 changes: 0 additions & 21 deletions
21
packages/expect-opentelemetry/src/matchers/service/to-send-http-request.test.ts
This file was deleted.
Oops, something went wrong.
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
44 changes: 44 additions & 0 deletions
44
packages/expect-opentelemetry/src/matchers/utils/filters.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,44 @@ | ||
import { opentelemetry } from '@traceloop/otel-proto'; | ||
import { stringCompare } from './comparators'; | ||
import { CompareOptions } from './compare-types'; | ||
|
||
export const filterByAttributeKey = ( | ||
spans: opentelemetry.proto.trace.v1.ISpan[], | ||
attName: string, | ||
) => | ||
spans.filter((span) => { | ||
span.attributes?.find((attribute) => { | ||
return attribute.key === attName; | ||
}); | ||
}); | ||
|
||
export const filterBySpanKind = ( | ||
spans: opentelemetry.proto.trace.v1.ISpan[], | ||
expected: opentelemetry.proto.trace.v1.Span.SpanKind, | ||
) => spans.filter((span) => span.kind === expected); | ||
|
||
export const filterByAttributeStringValue = ( | ||
spans: opentelemetry.proto.trace.v1.ISpan[], | ||
attName: string, | ||
attValue: string | RegExp, | ||
options?: CompareOptions, | ||
) => | ||
spans.filter((span) => { | ||
return span.attributes?.find( | ||
(attribute) => | ||
attribute.key === attName && | ||
stringCompare(attribute.value?.stringValue, attValue, options), | ||
); | ||
}); | ||
|
||
export const filterByAttributeIntValue = ( | ||
spans: opentelemetry.proto.trace.v1.ISpan[], | ||
attName: string, | ||
attValue: number, | ||
) => | ||
spans.filter((span) => { | ||
return span.attributes?.find( | ||
(attribute) => | ||
attribute.key === attName && attribute.value?.intValue === attValue, | ||
); | ||
}); |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './compare-types'; | ||
export * from './comparators'; | ||
export * from './filters'; |
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