-
Notifications
You must be signed in to change notification settings - Fork 133
Introduce built-in swift-distributed-tracing support #857
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
Open
ktoso
wants to merge
20
commits into
swift-server:main
Choose a base branch
from
ktoso:wip-trace-again
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2d9c03b
[Tracing] Initial tracing support implementation
ktoso 3ce7dc6
swift-format and remove hacky platform setting
ktoso 83efc63
[Tracing] fix availability issues
ktoso 5ede6ae
[Tracing] Further try to simplify availaabilty woes for call-sites
ktoso f7835c3
fix licenseignore to handle [email protected]
ktoso b746315
[CI] attempt to add CI action to test with disabled package traits
ktoso 939a544
Revert "[CI] attempt to add CI action to test with disabled package t…
ktoso 18252c7
fixup: Package.swift should be 5.10
ktoso 19ac881
minor compile fixup
ktoso c191e11
build: fix the 6.0 build, there's no package traits below 6.1
ktoso 072574a
depend on distributor tracing 1.3.0
ktoso 3bbfd56
Cleanup some leftovers and address some review comments
ktoso 91ea66e
Remove package trait, and cleanup sources; Handle failed HTTP responses
ktoso 7d774e4
main module does not need InMemoryTracer
ktoso 07c6c57
make attribute key customization private for now
ktoso 552286b
remove duplicated func
ktoso 8b30965
Fix attribute key to be body response size specifcially
ktoso 622a549
Address @glbrntt review comments; minor cleanups
ktoso 6610fa3
Update copyright year
ktoso 4026c0e
Merge branch 'main' into wip-trace-again
ktoso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+tracing.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the AsyncHTTPClient open source project | ||
// | ||
// Copyright (c) 2021 Apple Inc. and the AsyncHTTPClient project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Logging | ||
import NIOCore | ||
import NIOHTTP1 | ||
import Tracing | ||
|
||
import struct Foundation.URL | ||
ktoso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) | ||
extension HTTPClient { | ||
@inlinable | ||
func withRequestSpan( | ||
_ request: HTTPClientRequest, | ||
_ body: () async throws -> HTTPClientResponse | ||
) async rethrows -> HTTPClientResponse { | ||
guard let tracer = self.tracer else { | ||
return try await body() | ||
} | ||
|
||
return try await tracer.withSpan(request.method.rawValue, ofKind: .client) { span in | ||
let keys = self.configuration.tracing.attributeKeys | ||
span.attributes[keys.requestMethod] = request.method.rawValue | ||
// TODO: set more attributes on the span | ||
let response = try await body() | ||
|
||
// set response span attributes | ||
TracingSupport.handleResponseStatusCode(span, response.status, keys: tracing.attributeKeys) | ||
|
||
return response | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.