Skip to content

Commit 548438a

Browse files
authored
Merge pull request #6 from AthennaIO/develop
fix: add warning when context is not initialized
2 parents 6d44c2c + 68e1742 commit 548438a

4 files changed

Lines changed: 20 additions & 12 deletions

File tree

package-lock.json

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@athenna/otel",
3-
"version": "5.14.0",
3+
"version": "5.15.0",
44
"description": "OpenTelemetry package for Athenna.",
55
"license": "MIT",
66
"author": "João Lenon <lenon@athenna.io>",
@@ -75,7 +75,7 @@
7575
"@athenna/config": "^5.6.0",
7676
"@athenna/http": "^5.51.0",
7777
"@athenna/ioc": "^5.2.0",
78-
"@athenna/logger": "^5.15.0",
78+
"@athenna/logger": "^5.20.0",
7979
"@athenna/test": "^5.6.0",
8080
"@athenna/tsconfig": "^5.0.0",
8181
"@typescript-eslint/eslint-plugin": "^7.18.0",

src/exceptions/ContextNotInitializedException.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Exception } from '@athenna/common'
22

33
export class ContextNotInitializedException extends Exception {
4-
public constructor(message = 'Current request context store is not initialized') {
4+
public constructor(
5+
message = 'Current request context store is not initialized'
6+
) {
57
super({
68
code: 'E_CONTEXT_NOT_INITIALIZED',
79
message,

src/otel/OtelImpl.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
type Context
1717
} from '@opentelemetry/api'
1818

19+
import { Log } from '@athenna/logger'
1920
import { Config } from '@athenna/config'
2021
import { NodeSDK } from '@opentelemetry/sdk-node'
2122
import { Is, Options, Macroable } from '@athenna/common'
@@ -429,15 +430,19 @@ export class OtelImpl extends Macroable {
429430
*/
430431
private getCurrentContextStore(ctx?: Context) {
431432
if (Config.is('otel.enabled', false)) {
432-
throw new DisabledOtelException('OpenTelemetry is disabled and a context could not be retrieved')
433+
throw new DisabledOtelException(
434+
'OpenTelemetry is disabled and a context could not be retrieved'
435+
)
433436
}
434437

435438
const store = (ctx || context.active()).getValue(
436439
otelCurrentContextBagKey as any
437-
)
440+
)
438441

439442
if (!store || !(store instanceof Map)) {
440-
throw new ContextNotInitializedException()
443+
Log.channelOrVanilla('exception').error(new ContextNotInitializedException())
444+
445+
return new Map<string | symbol, unknown>()
441446
}
442447

443448
return store as Map<string | symbol, unknown>

0 commit comments

Comments
 (0)