Skip to content

Commit 7319465

Browse files
committed
chore: move error methods above finally to show real call order
Signed-off-by: Lukas Reining <[email protected]>
1 parent bf3e4cc commit 7319465

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

libs/hooks/open-telemetry/src/lib/traces/tracing-hooks.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ export class EventHook extends OpenTelemetryHook implements BaseHook {
2828
this.eventLogger = logs.getLogger(LIBRARY_NAME, LIBRARY_VERSION);
2929
}
3030

31-
finally(hookContext: Readonly<HookContext>, evaluationDetails: EvaluationDetails<FlagValue>) {
32-
const { name, attributes } = this.toEvaluationEvent(hookContext, evaluationDetails);
33-
this.eventLogger.emit({ eventName: name, attributes: attributes });
34-
}
35-
3631
error(_: HookContext, err: Error) {
3732
if (!this.excludeExceptions) {
3833
this.eventLogger.emit(this.toExceptionLogEvent(err));
3934
}
4035
}
4136

37+
finally(hookContext: Readonly<HookContext>, evaluationDetails: EvaluationDetails<FlagValue>) {
38+
const { name, attributes } = this.toEvaluationEvent(hookContext, evaluationDetails);
39+
this.eventLogger.emit({ eventName: name, attributes: attributes });
40+
}
41+
4242
/**
4343
* Converts an exception to an OpenTelemetry log event.
4444
* The event is compatible to https://opentelemetry.io/docs/specs/semconv/exceptions/exceptions-logs/
@@ -84,6 +84,12 @@ export class SpanEventHook extends OpenTelemetryHook implements BaseHook {
8484
super(options, logger);
8585
}
8686

87+
error(_: HookContext, err: Error) {
88+
if (!this.excludeExceptions) {
89+
trace.getActiveSpan()?.recordException(err);
90+
}
91+
}
92+
8793
finally(hookContext: Readonly<HookContext>, evaluationDetails: EvaluationDetails<FlagValue>) {
8894
const currentTrace = trace.getActiveSpan();
8995
if (!currentTrace) {
@@ -94,12 +100,6 @@ export class SpanEventHook extends OpenTelemetryHook implements BaseHook {
94100

95101
currentTrace.addEvent(name, attributes);
96102
}
97-
98-
error(_: HookContext, err: Error) {
99-
if (!this.excludeExceptions) {
100-
trace.getActiveSpan()?.recordException(err);
101-
}
102-
}
103103
}
104104

105105
const tracer = trace.getTracer(LIBRARY_NAME, LIBRARY_VERSION);
@@ -124,6 +124,13 @@ export class SpanHook extends OpenTelemetryHook implements BaseHook {
124124
hookContext.hookData.set(HookContextSpanKey, evaluationSpan);
125125
}
126126

127+
error(hookContext: Readonly<HookContext<FlagValue, SpanAttributesTracingHookData>>, err: Error) {
128+
if (!this.excludeExceptions) {
129+
const currentSpan = hookContext.hookData.get(HookContextSpanKey) ?? trace.getActiveSpan();
130+
currentSpan?.recordException(err);
131+
}
132+
}
133+
127134
finally(
128135
hookContext: Readonly<HookContext<FlagValue, SpanAttributesTracingHookData>>,
129136
evaluationDetails: EvaluationDetails<FlagValue>,
@@ -138,11 +145,4 @@ export class SpanHook extends OpenTelemetryHook implements BaseHook {
138145
currentSpan.setAttributes(attributes);
139146
currentSpan.end();
140147
}
141-
142-
error(hookContext: Readonly<HookContext<FlagValue, SpanAttributesTracingHookData>>, err: Error) {
143-
if (!this.excludeExceptions) {
144-
const currentSpan = hookContext.hookData.get(HookContextSpanKey) ?? trace.getActiveSpan();
145-
currentSpan?.recordException(err);
146-
}
147-
}
148148
}

0 commit comments

Comments
 (0)