Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure the serviceContext is always injected into the outgoing request #133

Merged
merged 1 commit into from
Sep 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Sources/SmokeHTTPClient/HTTPOperationsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ extension HTTPOperationsClient {
requestComponents: requestComponents,
httpMethod: httpMethod,
invocationContext: invocationContext,
span: span)
span: span,
fallbackServiceContext: serviceContext)

do {
let successResult = try await responseFuture.get()
Expand Down Expand Up @@ -346,7 +347,8 @@ extension HTTPOperationsClient {
requestComponents: HTTPRequestComponents,
httpMethod: HTTPMethod,
invocationContext: HTTPClientInvocationContext<InvocationReportingType, HandlerDelegateType>,
span: Span? = nil) throws
span: Span? = nil,
fallbackServiceContext: ServiceContext? = nil) throws
-> (EventLoopFuture<HTTPClient.Response>, InvocationReportingType.TraceContextType.OutwardsRequestContext) {

let endpointHostName = endpointOverride?.host ?? self.endpointHostName
Expand Down Expand Up @@ -383,9 +385,12 @@ extension HTTPOperationsClient {
span.attributes["http.flavor"] = "1.1"
span.attributes["http.user_agent"] = requestHeaders.first(name: "user-agent")
span.attributes["http.request_content_length"] = requestHeaders.first(name: "content-length")

}

let serviceContext = span?.context ?? fallbackServiceContext
if let serviceContext = serviceContext {
InstrumentationSystem.instrument.inject(
span.context,
serviceContext,
into: &requestHeaders,
using: HTTPHeadersInjector()
)
Expand Down
Loading