1- import { TraceoMetric , TraceoMetricType , DataPointType , Dictionary , MetricData , ReadableSpan , ResourceMetrics } from "@traceo-sdk/node-core" ;
1+ import { TraceoMetric , TraceoMetricType , DataPointType , Dictionary , MetricData , ReadableSpan , ResourceMetrics , SpanStatusCode } from "@traceo-sdk/node-core" ;
22import { TraceoSpan } from "./types" ;
3- import { HrTime } from "@opentelemetry/api" ;
3+ import { HrTime , SpanKind } from "@opentelemetry/api" ;
44
55/**
66 * Mapper to map OpenTelemetry objects to Traceo responses.
@@ -50,7 +50,7 @@ export class OtelMapper {
5050 public static mapSpans ( otelSpans : ReadableSpan [ ] ) : TraceoSpan [ ] {
5151 return otelSpans . map ( ( otel ) => ( {
5252 name : otel . name ,
53- kind : otel . kind . toString ( ) ,
53+ kind : this . getSpanKind ( otel . kind ) ,
5454 status : otel . status . code . toString ( ) ,
5555 statusMessage : otel . status . message ,
5656 traceId : otel . spanContext ( ) . traceId ,
@@ -64,6 +64,23 @@ export class OtelMapper {
6464 } ) ) ;
6565 }
6666
67+ private static getSpanKind ( code : SpanKind ) : string {
68+ switch ( code ) {
69+ case SpanKind . INTERNAL :
70+ return "INTERNAL" ;
71+ case SpanKind . SERVER :
72+ return "SERVER" ;
73+ case SpanKind . CLIENT :
74+ return "CLIENT" ;
75+ case SpanKind . PRODUCER :
76+ return "PRODUCER" ;
77+ case SpanKind . CONSUMER :
78+ return "CONSUMER" ;
79+ default :
80+ return "" ;
81+ }
82+ }
83+
6784 private static getEpochNanos ( time : HrTime ) : number {
6885 return time [ 0 ] + time [ 1 ] / 1e9 ;
6986 }
0 commit comments