Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/otel",
"version": "5.14.0",
"version": "5.15.0",
"description": "OpenTelemetry package for Athenna.",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down Expand Up @@ -75,7 +75,7 @@
"@athenna/config": "^5.6.0",
"@athenna/http": "^5.51.0",
"@athenna/ioc": "^5.2.0",
"@athenna/logger": "^5.15.0",
"@athenna/logger": "^5.20.0",
"@athenna/test": "^5.6.0",
"@athenna/tsconfig": "^5.0.0",
"@typescript-eslint/eslint-plugin": "^7.18.0",
Expand Down
4 changes: 3 additions & 1 deletion src/exceptions/ContextNotInitializedException.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Exception } from '@athenna/common'

export class ContextNotInitializedException extends Exception {
public constructor(message = 'Current request context store is not initialized') {
public constructor(
message = 'Current request context store is not initialized'
) {
super({
code: 'E_CONTEXT_NOT_INITIALIZED',
message,
Expand Down
11 changes: 8 additions & 3 deletions src/otel/OtelImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type Context
} from '@opentelemetry/api'

import { Log } from '@athenna/logger'
import { Config } from '@athenna/config'
import { NodeSDK } from '@opentelemetry/sdk-node'
import { Is, Options, Macroable } from '@athenna/common'
Expand Down Expand Up @@ -429,15 +430,19 @@ export class OtelImpl extends Macroable {
*/
private getCurrentContextStore(ctx?: Context) {
if (Config.is('otel.enabled', false)) {
throw new DisabledOtelException('OpenTelemetry is disabled and a context could not be retrieved')
throw new DisabledOtelException(
'OpenTelemetry is disabled and a context could not be retrieved'
)
}

const store = (ctx || context.active()).getValue(
otelCurrentContextBagKey as any
)
)

if (!store || !(store instanceof Map)) {
throw new ContextNotInitializedException()
Log.channelOrVanilla('exception').error(new ContextNotInitializedException())

return new Map<string | symbol, unknown>()
}

return store as Map<string | symbol, unknown>
Expand Down
Loading