|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift Distributed Tracing open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2020 Moritz Lang and the Swift Tracing project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// |
| 10 | +// SPDX-License-Identifier: Apache-2.0 |
| 11 | +// |
| 12 | +//===----------------------------------------------------------------------===// |
| 13 | + |
| 14 | +import TracingInstrumentation |
| 15 | + |
| 16 | +extension SpanAttributes { |
| 17 | + /// Semantic conventions for HTTP spans. |
| 18 | + public var http: HTTPAttributes { |
| 19 | + get { |
| 20 | + .init(attributes: self) |
| 21 | + } |
| 22 | + set { |
| 23 | + self = newValue.attributes |
| 24 | + } |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +/// Semantic conventions for HTTP spans as defined in the OpenTelemetry spec. |
| 29 | +@dynamicMemberLookup |
| 30 | +public struct HTTPAttributes: SpanAttributeNamespace { |
| 31 | + public var attributes: SpanAttributes |
| 32 | + |
| 33 | + public init(attributes: SpanAttributes) { |
| 34 | + self.attributes = attributes |
| 35 | + } |
| 36 | + |
| 37 | + public struct NestedAttributes: NestedSpanAttributesProtocol { |
| 38 | + public init() {} |
| 39 | + |
| 40 | + /// HTTP request method. E.g. "GET". |
| 41 | + public var method: SpanAttributeKey<String> { "http.method" } |
| 42 | + |
| 43 | + /// Full HTTP request URL in the form scheme://host[:port]/path?query[#fragment]. |
| 44 | + /// Usually the fragment is not transmitted over HTTP, but if it is known, it should be included nevertheless. |
| 45 | + public var url: SpanAttributeKey<String> { "http.url" } |
| 46 | + |
| 47 | + /// The full request target as passed in a HTTP request line or equivalent, e.g. "/path/12314/?q=ddds#123". |
| 48 | + public var target: SpanAttributeKey<String> { "http.target" } |
| 49 | + |
| 50 | + /// The value of the HTTP host header. When the header is empty or not present, this attribute should be the same. |
| 51 | + public var host: SpanAttributeKey<String> { "http.host" } |
| 52 | + |
| 53 | + /// The URI scheme identifying the used protocol: "http" or "https" |
| 54 | + public var scheme: SpanAttributeKey<String> { "http.scheme" } |
| 55 | + |
| 56 | + /// HTTP response status code. E.g. 200. |
| 57 | + public var statusCode: SpanAttributeKey<Int> { "http.status_code" } |
| 58 | + |
| 59 | + /// HTTP reason phrase. E.g. "OK". |
| 60 | + public var statusText: SpanAttributeKey<String> { "http.status_text" } |
| 61 | + |
| 62 | + /// Kind of HTTP protocol used: "1.0", "1.1", "2", "SPDY" or "QUIC". |
| 63 | + public var flavor: SpanAttributeKey<String> { "http.flavor" } |
| 64 | + |
| 65 | + /// Value of the HTTP User-Agent header sent by the client. |
| 66 | + public var userAgent: SpanAttributeKey<String> { "http.user_agent" } |
| 67 | + |
| 68 | + /// The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, |
| 69 | + /// but not always, present as the Content-Length header. For requests using transport encoding, this should be the |
| 70 | + /// compressed size. |
| 71 | + public var requestContentLength: SpanAttributeKey<Int> { "http.request_content_length" } |
| 72 | + |
| 73 | + /// The size of the uncompressed request payload body after transport decoding. Not set if transport encoding not used. |
| 74 | + public var requestContentLengthUncompressed: SpanAttributeKey<Int> { |
| 75 | + "http.request_content_length_uncompressed" |
| 76 | + } |
| 77 | + |
| 78 | + /// The size of the response payload body in bytes. This is the number of bytes transferred excluding headers and |
| 79 | + /// is often, but not always, present as the Content-Length header. For requests using transport encoding, this |
| 80 | + /// should be the compressed size. |
| 81 | + public var responseContentLength: SpanAttributeKey<Int> { "http.response_content_length" } |
| 82 | + |
| 83 | + /// The size of the uncompressed response payload body after transport decoding. Not set if transport encoding not used. |
| 84 | + public var responseContentLengthUncompressed: SpanAttributeKey<Int> { |
| 85 | + "http.response_content_length_uncompressed" |
| 86 | + } |
| 87 | + |
| 88 | + /// The primary server name of the matched virtual host. This should be obtained via configuration. |
| 89 | + /// If no such configuration can be obtained, this attribute MUST NOT be set (`net.hostName` should be used instead). |
| 90 | + public var serverName: SpanAttributeKey<String> { "http.server_name" } |
| 91 | + |
| 92 | + /// The matched route (path template). E.g. "/users/:userID?". |
| 93 | + public var serverRoute: SpanAttributeKey<String> { "http.route" } |
| 94 | + |
| 95 | + /// The IP address of the original client behind all proxies, if known (e.g. from X-Forwarded-For). |
| 96 | + /// Note that this is not necessarily the same as `net.peerIP`, which would identify the network-level peer, |
| 97 | + /// which may be a proxy. |
| 98 | + public var serverClientIP: SpanAttributeKey<String> { "http.client_ip" } |
| 99 | + } |
| 100 | +} |
0 commit comments