-
-
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.
* chore: update module to ES12 * chore: app versio bump and test pod update * chore: update eslint to es12 module * chore: update test in package to point to mjs * chore: updates pod test file name
- Loading branch information
Showing
7 changed files
with
3,961 additions
and
1,006 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
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// tracing.test.mjs | ||
import { setupTracing } from './index.mjs'; | ||
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; | ||
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base'; | ||
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc'; | ||
|
||
// Mocking external dependencies | ||
jest.mock('@opentelemetry/sdk-trace-node', () => { | ||
const originalModule = jest.requireActual('@opentelemetry/sdk-trace-node'); | ||
return { | ||
...originalModule, | ||
NodeTracerProvider: jest.fn().mockImplementation(() => ({ | ||
addSpanProcessor: jest.fn(), | ||
register: jest.fn(), | ||
getTracer: jest.fn().mockReturnValue({}), | ||
resource: { | ||
attributes: {}, | ||
}, | ||
})), | ||
}; | ||
}); | ||
|
||
jest.mock('@opentelemetry/sdk-trace-base', () => ({ | ||
BatchSpanProcessor: jest.fn(), | ||
SpanProcessor: jest.fn(), | ||
})); | ||
|
||
jest.mock('@opentelemetry/exporter-trace-otlp-grpc', () => ({ | ||
OTLPTraceExporter: jest.fn(), | ||
})); | ||
|
||
describe('setupTracing', () => { | ||
beforeEach(() => { | ||
// Clear all instances and calls to constructor and all methods: | ||
NodeTracerProvider.mockClear(); | ||
BatchSpanProcessor.mockClear(); | ||
OTLPTraceExporter.mockClear(); | ||
}); | ||
|
||
it('should create a tracer with default parameters', () => { | ||
const tracer = setupTracing('test-service'); | ||
expect(NodeTracerProvider).toHaveBeenCalledTimes(1); | ||
expect(BatchSpanProcessor).toHaveBeenCalledTimes(1); | ||
expect(OTLPTraceExporter).toHaveBeenCalledWith({ | ||
serviceName: 'test-service', | ||
url: null, | ||
}); | ||
expect(tracer).toBeDefined(); | ||
}); | ||
|
||
it('should create a tracer with custom application name and endpoint', () => { | ||
const tracer = setupTracing('test-service', 'custom-app', 'custom-endpoint'); | ||
expect(NodeTracerProvider).toHaveBeenCalledTimes(1); | ||
expect(BatchSpanProcessor).toHaveBeenCalledTimes(1); | ||
expect(OTLPTraceExporter).toHaveBeenCalledWith({ | ||
serviceName: 'test-service', | ||
url: 'custom-endpoint', | ||
}); | ||
expect(tracer).toBeDefined(); | ||
}); | ||
|
||
}); |
Oops, something went wrong.