You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.
This is related with #46 but goes one step forward in order to address #72 (comment),
not only we pass the context but also use TracingInstrument to record the request and response.
My worry is that even if/when AsyncHTTPClientAPI is extended to pass the context,
dependency on Instrumentation and NIOInstrumentation maybe to much to ask them (?)
classBetterHTTPClient{privateletclient:HTTPClientinit(eventLoopGroup:EventLoopGroup?=nil){
if let eventLoopGroup = eventLoopGroup {
client =HTTPClient(eventLoopGroupProvider:.shared(eventLoopGroup))}else{
client =HTTPClient(eventLoopGroupProvider:.createNew)}}deinit{try? client.syncShutdown()}func execute(request:HTTPClient.Request, baggage:BaggageContext)->NIO.EventLoopFuture<AsyncHTTPClient.HTTPClient.Response>{lettracer=InstrumentationSystem.tracer
varspan= tracer.startHTTPSpan(request: request, context: baggage)varrequest= request
tracer.inject(span.baggage, into:&request.headers, using:HTTPHeadersInjector())return client.execute(request: request).always{ result in
switch result {case.success(let response):
span.setHTTPAttributes(response: response)case.failure(let error):// TODO: span does not expose a way to recoer an error at the moment, see https://github.com/slashmo/gsoc-swift-tracing/issues/90
span.addEvent(.init(name:"Error \(error)"))}
span.end()}}}privateextensionTracingInstrument{func startHTTPSpan(request:HTTPClient.Request, context:BaggageContext)->Span{// TODO: create name per https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.mdvarspan=startSpan(named:"HTTP \(request.url)", context: context)// TODO: preferably the attributes would be passed in ctor
span.setHTTPAttributes(request: request)return span
}}privateextensionSpan{mutatingfunc setHTTPAttributes(request:HTTPClient.Request){setAttribute(request.method.rawValue, forKey:OpenTelemetry.SpanAttributes.HTTP.method)setAttribute(request.url.absoluteString, forKey:OpenTelemetry.SpanAttributes.HTTP.url)}mutatingfunc setHTTPAttributes(response:HTTPClient.Response){setAttribute(response.status.code, forKey:OpenTelemetry.SpanAttributes.HTTP.statusCode)setAttribute(response.body?.readableBytes ??-1, forKey:OpenTelemetry.SpanAttributes.HTTP.responseContentLength)}}
enumOpenTelemetry{enumSpanAttributes{/// [Semantic conventions for HTTP spans](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md)enumHTTP{/// HTTP request method. E.g. "GET". Required.staticletmethod="http.method"/// Full HTTP request URL in the form `scheme://host[:port]/path?query[#fragment]`./// Usually the fragment is not transmitted over HTTP, but if it is known, it should be included nevertheless.staticleturl="http.url"/// HTTP response status code. E.g. `200` (integer)staticletstatusCode="http.status_code"/// The size of the response payload body in bytes./// This is the number of bytes transferred excluding headers and is often, but not always, present as the `Content-Length` header./// For requests using transport encoding, this should be the compressed size.staticletresponseContentLength="http.response_content_length"}}}
The text was updated successfully, but these errors were encountered:
It's not "too much to ask" wrt. instrumentation, we work closely with that team and we (the entire SSWG) want tracing to just work across all the core projects – when we say we're going to instrument the client you can trust us that it will happen 😉
Yup, that's the rough shape how an instrumentation will look like more or less 👍
This is related with #46 but goes one step forward in order to address #72 (comment),
not only we pass the context but also use
TracingInstrument
to record the request and response.My worry is that even if/when
AsyncHTTPClient
API is extended to pass the context,dependency on
Instrumentation
andNIOInstrumentation
maybe to much to ask them (?)I made a quick proof of concept implementation in pokryfka/aws-xray-sdk-swift#16
The text was updated successfully, but these errors were encountered: