Skip to content

Commit 650bf73

Browse files
committed
feat: adding OpenTelemetry option
1 parent 92362fb commit 650bf73

23 files changed

+2142
-152
lines changed

__tests__/dsl/journey.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323
*
2424
*/
2525

26+
import { trace } from '@opentelemetry/api';
2627
import { Journey, Step } from '../../src/dsl';
28+
import { addMonitorConfigAttributesToSpan } from '../../src/otel';
29+
30+
jest.mock('../../src/otel');
31+
jest.spyOn(trace, 'getActiveSpan').mockImplementation(() => 'span' as any);
2732

2833
const noop = () => {};
2934
describe('Journey', () => {
@@ -44,4 +49,14 @@ describe('Journey', () => {
4449
expect(s2).toBeInstanceOf(Step);
4550
expect(journey.steps.length).toBe(2);
4651
});
52+
53+
it('updates span when otel enabled and monitor config is added', () => {
54+
const journey = new Journey({ name: 'j1' }, noop);
55+
journey._updateMonitor('config' as any);
56+
expect(trace.getActiveSpan).toHaveBeenCalled();
57+
expect(addMonitorConfigAttributesToSpan).toHaveBeenCalledWith(
58+
'span',
59+
'config'
60+
);
61+
});
4762
});

__tests__/helper.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
microSecsToSeconds,
3535
wrapFnWithLocation,
3636
isMatch,
37+
maskCredentialsInURL,
3738
} from '../src/helpers';
3839

3940
it('indent message with seperator', () => {
@@ -146,3 +147,12 @@ it('match tags and names', () => {
146147
expect(isMatch(['bar'], 'foo', undefined, 'ba*')).toBe(true);
147148
expect(isMatch(['bar'], 'foo', undefined, 'test*')).toBe(false);
148149
});
150+
151+
it('mask credentials in URL', () => {
152+
expect(maskCredentialsInURL('https://user:password@example.com')).toBe(
153+
'https://***:***@example.com/'
154+
);
155+
expect(maskCredentialsInURL('https://example.com')).toBe(
156+
'https://example.com/'
157+
);
158+
});

__tests__/options.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('options', () => {
4444
sandbox: false,
4545
screenshots: 'on',
4646
dryRun: true,
47+
otel: true,
4748
match: 'check*',
4849
pauseOnError: true,
4950
config: join(__dirname, 'fixtures', 'synthetics.config.ts'),
@@ -52,9 +53,11 @@ describe('options', () => {
5253
environment: 'test',
5354
params: {},
5455
screenshots: 'on',
56+
otel: false,
5557
});
5658
expect(await normalizeOptions(cliArgs)).toMatchObject({
5759
dryRun: true,
60+
otel: true,
5861
environment: 'test',
5962
grepOpts: { match: 'check*' },
6063
params: {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2020-present, Elastic NV
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
*/
25+
26+
import { OtelTraceable } from '../../src/otel';
27+
28+
describe('OtelTraceable', () => {
29+
it('has no span and context after init', () => {
30+
const traceable = new OtelTraceable();
31+
expect(traceable._getSpan()).toBeUndefined();
32+
expect(traceable._getContext()).toBeUndefined();
33+
});
34+
35+
it('sets and clears span and context', () => {
36+
const traceable = new OtelTraceable();
37+
38+
traceable._setSpan('span' as any);
39+
traceable._setContext('context' as any);
40+
expect(traceable._getSpan()).toBe('span');
41+
expect(traceable._getContext()).toBe('context');
42+
43+
traceable._setSpan();
44+
traceable._setContext();
45+
expect(traceable._getSpan()).toBeUndefined();
46+
expect(traceable._getContext()).toBeUndefined();
47+
});
48+
});

__tests__/plugins/browser-console.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ import { wsEndpoint } from '../utils/test-config';
3131

3232
describe('BrowserConsole', () => {
3333
let server: Server;
34-
const currentStep = { name: 'test-step', index: 0 };
34+
const currentStep = {
35+
name: 'test-step',
36+
index: 0,
37+
_getSpan: () => undefined,
38+
};
3539
beforeAll(async () => {
3640
server = await Server.create();
3741
});

0 commit comments

Comments
 (0)