|
@@ -9,8 +9,10 @@ import {
|
|
|
|
|
|
export class SQSOpenTelemetryEventMessageHandler implements DomainEventMessageHandlerInterface {
|
|
export class SQSOpenTelemetryEventMessageHandler implements DomainEventMessageHandlerInterface {
|
|
private currentSpan: OpenTelemetryApi.Span | undefined
|
|
private currentSpan: OpenTelemetryApi.Span | undefined
|
|
|
|
+ private internalSpan: OpenTelemetryApi.Span | undefined
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
|
|
+ private serviceName: string,
|
|
private handlers: Map<string, DomainEventHandlerInterface>,
|
|
private handlers: Map<string, DomainEventHandlerInterface>,
|
|
private logger: Logger,
|
|
private logger: Logger,
|
|
) {}
|
|
) {}
|
|
@@ -35,18 +37,26 @@ export class SQSOpenTelemetryEventMessageHandler implements DomainEventMessageHa
|
|
|
|
|
|
const tracer = OpenTelemetryApi.trace.getTracer('sqs-handler')
|
|
const tracer = OpenTelemetryApi.trace.getTracer('sqs-handler')
|
|
|
|
|
|
- this.currentSpan = tracer.startSpan(domainEvent.type)
|
|
|
|
|
|
+ this.currentSpan = tracer.startSpan(this.serviceName, { kind: OpenTelemetryApi.SpanKind.CONSUMER })
|
|
|
|
+ this.internalSpan = tracer.startSpan(domainEvent.type, { kind: OpenTelemetryApi.SpanKind.INTERNAL })
|
|
|
|
|
|
await handler.handle(domainEvent)
|
|
await handler.handle(domainEvent)
|
|
|
|
|
|
|
|
+ this.internalSpan.end()
|
|
this.currentSpan.end()
|
|
this.currentSpan.end()
|
|
|
|
|
|
|
|
+ this.internalSpan = undefined
|
|
this.currentSpan = undefined
|
|
this.currentSpan = undefined
|
|
}
|
|
}
|
|
|
|
|
|
async handleError(error: Error): Promise<void> {
|
|
async handleError(error: Error): Promise<void> {
|
|
|
|
+ if (this.internalSpan) {
|
|
|
|
+ this.internalSpan.recordException(error)
|
|
|
|
+ this.internalSpan.end()
|
|
|
|
+ this.internalSpan = undefined
|
|
|
|
+ }
|
|
|
|
+
|
|
if (this.currentSpan) {
|
|
if (this.currentSpan) {
|
|
- this.currentSpan.recordException(error)
|
|
|
|
this.currentSpan.end()
|
|
this.currentSpan.end()
|
|
this.currentSpan = undefined
|
|
this.currentSpan = undefined
|
|
}
|
|
}
|