@@ -20,6 +20,7 @@ import NIOFoundationCompat
20
20
import NIOHTTP1
21
21
import SwiftProtobuf
22
22
import TracingInstrumentation
23
+ import OpenTelemetryInstrumentationSupport
23
24
24
25
/// Incoming gRPC package with a fixed message type.
25
26
///
@@ -350,15 +351,18 @@ extension HTTP1ToGRPCServerCodec: ChannelOutboundHandler {
350
351
headers. add ( name: GRPCHeaderName . acceptEncoding, value: acceptEncoding)
351
352
}
352
353
354
+ let responseStatus = HTTPResponseStatus . ok
353
355
context. write (
354
356
self
355
357
. wrapOutboundOut ( . head( HTTPResponseHead (
356
358
version: version,
357
- status: . ok ,
359
+ status: responseStatus ,
358
360
headers: headers
359
361
) ) ) ,
360
362
promise: promise
361
363
)
364
+ self . span. attributes [ SpanAttributeName . HTTP. statusCode] = . int( Int ( responseStatus. code) )
365
+ self . span. attributes [ SpanAttributeName . HTTP. statusText] = . string( responseStatus. reasonPhrase)
362
366
self . outboundState = . expectingBodyOrStatus
363
367
364
368
case let . message( messageContext) :
@@ -392,6 +396,7 @@ extension HTTP1ToGRPCServerCodec: ChannelOutboundHandler {
392
396
compressed: messageContext. compressed
393
397
)
394
398
context. write ( self . wrapOutboundOut ( . body( . byteBuffer( messageBuffer) ) ) , promise: promise)
399
+ self . span. attributes [ SpanAttributeName . HTTP. responseContentLength] = . int( messageBuffer. readableBytes)
395
400
}
396
401
} catch {
397
402
let error = GRPCError . SerializationFailure ( ) . captureContext ( )
@@ -462,6 +467,7 @@ extension HTTP1ToGRPCServerCodec: ChannelOutboundHandler {
462
467
responseTextBuffer. clear ( minimumCapacity: UInt32 ( encodedData. utf8. count) )
463
468
responseTextBuffer. writeString ( encodedData)
464
469
470
+ self . span. attributes [ SpanAttributeName . HTTP. responseContentLength] = . int( encodedData. utf8. count)
465
471
// After collecting all response for gRPC Web connections, send one final aggregated
466
472
// response.
467
473
context. write (
0 commit comments