Skip to content

Commit 454b9a9

Browse files
authored
impl(gax-internal): Define OpenTelemetry key constants for HttpSpanInfo (#3367)
* impl(gax-internal): Define OpenTelemetry key constants for HttpSpanInfo * style(gax-internal): Update doc comments in observability.rs
1 parent 772a84f commit 454b9a9

File tree

1 file changed

+137
-19
lines changed

1 file changed

+137
-19
lines changed

src/gax-internal/src/observability.rs

Lines changed: 137 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,88 @@
1717
use crate::options::InstrumentationClientInfo;
1818
use gax::options::RequestOptions;
1919

20+
// OpenTelemetry Semantic Convention Keys
21+
// See https://opentelemetry.io/docs/specs/semconv/http/http-spans/
22+
23+
/// Span Kind for OpenTelemetry interop.
24+
///
25+
/// Always "Client" for a span representing an outbound HTTP request.
26+
const KEY_OTEL_KIND: &str = "otel.kind";
27+
/// Span Name for OpenTelemetry interop.
28+
///
29+
/// If `url.template` is available use "{http.request.method} {url.template}", otherwise use "{http.request.method}".
30+
const KEY_OTEL_NAME: &str = "otel.name";
31+
/// Span Status for OpenTelemetry interop.
32+
///
33+
/// Use "Error" for unrecoverable errors like network issues or 5xx status codes.
34+
/// Otherwise, leave "Unset" (including for 4xx codes on CLIENT spans).
35+
const KEY_OTEL_STATUS: &str = "otel.status";
36+
37+
/// The RPC system used.
38+
///
39+
/// Always "http" for REST calls.
40+
const KEY_RPC_SYSTEM: &str = "rpc.system";
41+
/// The HTTP request method.
42+
///
43+
/// Examples: GET, POST, HEAD.
44+
const KEY_HTTP_REQUEST_METHOD: &str = "http.request.method";
45+
/// The destination host name or IP address.
46+
///
47+
/// Examples: myservice.googleapis.com, myservice-staging.sandbox.googleapis.com, 10.0.0.1
48+
const KEY_SERVER_ADDRESS: &str = "server.address";
49+
/// The destination port number.
50+
///
51+
/// Examples: 443, 8080
52+
const KEY_SERVER_PORT: &str = "server.port";
53+
/// The absolute URL of the request.
54+
///
55+
/// Example: https://www.foo.bar/search?q=OpenTelemetry
56+
const KEY_URL_FULL: &str = "url.full";
57+
/// The URI scheme component.
58+
///
59+
/// Examples: http, https
60+
const KEY_URL_SCHEME: &str = "url.scheme";
61+
/// The low-cardinality template of the absolute path.
62+
///
63+
/// Example: /v2/locations/{location}/projects/{project}/
64+
const KEY_URL_TEMPLATE: &str = "url.template";
65+
/// The nominal domain from the original URL.
66+
///
67+
/// Example: myservice.googleapis.com
68+
const KEY_URL_DOMAIN: &str = "url.domain";
69+
70+
/// The numeric HTTP response status code.
71+
///
72+
/// Examples: 200, 404, 500
73+
const KEY_HTTP_RESPONSE_STATUS_CODE: &str = "http.response.status_code";
74+
/// A low-cardinality classification of the error.
75+
///
76+
/// For HTTP status codes >= 400, this is the status code as a string.
77+
/// For network errors, use a short identifier like TIMEOUT, CONNECTION_ERROR.
78+
const KEY_ERROR_TYPE: &str = "error.type";
79+
/// The ordinal number of times this request has been resent.
80+
///
81+
/// None for the first attempt.
82+
const KEY_HTTP_REQUEST_RESEND_COUNT: &str = "http.request.resend_count";
83+
84+
// Custom GCP Attributes
85+
/// The Google Cloud service name.
86+
///
87+
/// Examples: appengine, run, firestore
88+
const KEY_GCP_CLIENT_SERVICE: &str = "gcp.client.service";
89+
/// The client library version.
90+
///
91+
/// Example: v1.0.2
92+
const KEY_GCP_CLIENT_VERSION: &str = "gcp.client.version";
93+
/// The client library repository.
94+
///
95+
/// Always "googleapis/google-cloud-rust".
96+
const KEY_GCP_CLIENT_REPO: &str = "gcp.client.repo";
97+
/// The client library crate name.
98+
///
99+
/// Example: google-cloud-storage
100+
const KEY_GCP_CLIENT_ARTIFACT: &str = "gcp.client.artifact";
101+
20102
#[derive(Debug, Clone, PartialEq)]
21103
pub(crate) enum OtelStatus {
22104
Unset,
@@ -44,48 +126,84 @@ impl OtelStatus {
44126
#[derive(Debug, Clone)]
45127
pub(crate) struct HttpSpanInfo {
46128
// Attributes for OpenTelemetry SDK interop
47-
/// Span Kind. Always CLIENT for a span representing an outbound HTTP request.
129+
/// The span kind for OpenTelemetry interop.
130+
///
131+
/// Always "Client" for a span representing an outbound HTTP request.
48132
otel_kind: String,
49-
/// Span Name. Recommended to be "{http.request.method} {url.template}" if url.template is available, otherwise "{http.request.method}".
133+
/// The span name for OpenTelemetry interop.
134+
///
135+
/// If `url.template` is available use "{http.request.method} {url.template}", otherwise use "{http.request.method}".
50136
otel_name: String,
51-
/// Span Status. Set to Error in the event of an unrecoverable error, for example network error, 5xx status codes. Unset otherwise (including 4xx codes for CLIENT spans).
137+
/// The span status for OpenTelemetry interop.
138+
///
139+
/// Use "Error" for unrecoverable errors like network issues or 5xx status codes.
140+
/// Otherwise, leave "Unset" (including for 4xx codes on CLIENT spans).
52141
otel_status: OtelStatus,
53142

54143
// OpenTelemetry Semantic Conventions
55-
/// Which RPC system is being used. Set to "http" for REST calls.
144+
/// The RPC system used.
145+
///
146+
/// Always "http" for REST calls.
56147
rpc_system: String,
57-
/// The HTTP request method, for example GET; POST; HEAD.
148+
/// The HTTP request method.
149+
///
150+
/// Examples: GET, POST, HEAD.
58151
http_request_method: String,
59-
/// The actual destination host name or IP address. May differ from the URL's host if overridden, for example myservice.googleapis.com; myservice-staging.sandbox.googleapis.com; 10.0.0.1.
152+
/// The destination host name or IP address.
153+
///
154+
/// Examples: myservice.googleapis.com, myservice-staging.sandbox.googleapis.com, 10.0.0.1
60155
server_address: String,
61-
/// The actual destination port number. May differ from the URL's port if overridden, for example 443; 8080.
156+
/// The destination port number.
157+
///
158+
/// Examples: 443, 8080
62159
server_port: i64,
63-
/// The absolute URL of the request, for example https://www.foo.bar/search?q=OpenTelemetry.
160+
/// The absolute URL of the request.
161+
///
162+
/// Example: https://www.foo.bar/search?q=OpenTelemetry
64163
url_full: String,
65-
/// The URI scheme component identifying the used protocol, for example http; https.
164+
/// The URI scheme component.
165+
///
166+
/// Examples: http, https
66167
url_scheme: Option<String>,
67-
/// The low-cardinality template of the absolute path, for example /v2/locations/{location}/projects/{project}/.
168+
/// The low-cardinality template of the absolute path.
169+
///
170+
/// Example: /v2/locations/{location}/projects/{project}/
68171
url_template: Option<String>,
69-
/// The nominal domain from the original URL, representing the intended service, for example myservice.googleapis.com.
172+
/// The nominal domain from the original URL.
173+
///
174+
/// Example: myservice.googleapis.com
70175
url_domain: Option<String>,
71176

72-
/// The numeric HTTP response status code, for example 200; 404; 500.
177+
/// The numeric HTTP response status code.
178+
///
179+
/// Examples: 200, 404, 500
73180
http_response_status_code: Option<i64>,
74-
/// A low cardinality a class of error the operation ended with.
181+
/// A low-cardinality classification of the error.
182+
///
75183
/// For HTTP status codes >= 400, this is the status code as a string.
76-
/// For network errors, a short identifier like TIMEOUT, CONNECTION_ERROR.
184+
/// For network errors, use a short identifier like TIMEOUT, CONNECTION_ERROR.
77185
error_type: Option<String>,
78-
/// The ordinal number of times this request has been resent (e.g., due to retries or redirects). None for the first attempt.
186+
/// The ordinal number of times this request has been resent.
187+
///
188+
/// None for the first attempt.
79189
http_request_resend_count: Option<i64>,
80190

81191
// Custom GCP Attributes
82-
/// Identifies the Google Cloud service, for example appengine; run; firestore.
192+
/// The Google Cloud service name.
193+
///
194+
/// Examples: appengine, run, firestore
83195
gcp_client_service: Option<String>,
84-
/// The version of the client library, for example v1.0.2.
196+
/// The client library version.
197+
///
198+
/// Example: v1.0.2
85199
gcp_client_version: Option<String>,
86-
/// The repository of the client library. Always "googleapis/google-cloud-rust".
200+
/// The client library repository.
201+
///
202+
/// Always "googleapis/google-cloud-rust".
87203
gcp_client_repo: String,
88-
/// The crate name of the client library, for example google-cloud-storage.
204+
/// The client library crate name.
205+
///
206+
/// Example: google-cloud-storage
89207
gcp_client_artifact: Option<String>,
90208
}
91209

0 commit comments

Comments
 (0)