Skip to content

Commit 5981c19

Browse files
committed
impl(gax-internal): Define OpenTelemetry key constants for HttpSpanInfo
1 parent 576ab46 commit 5981c19

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

src/gax-internal/src/observability.rs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,50 @@
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. Always CLIENT for a span representing an outbound HTTP request.
24+
const KEY_OTEL_KIND: &str = "otel.kind";
25+
/// Span Name for OpenTelemetry interop. Recommended to be "{http.request.method} {url.template}" if url.template is available, otherwise "{http.request.method}".
26+
const KEY_OTEL_NAME: &str = "otel.name";
27+
/// Span Status for OpenTelemetry interop. 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).
28+
const KEY_OTEL_STATUS: &str = "otel.status";
29+
30+
/// Which RPC system is being used. Set to "http" for REST calls.
31+
const KEY_RPC_SYSTEM: &str = "rpc.system";
32+
/// The HTTP request method, for example GET; POST; HEAD.
33+
const KEY_HTTP_REQUEST_METHOD: &str = "http.request.method";
34+
/// 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.
35+
const KEY_SERVER_ADDRESS: &str = "server.address";
36+
/// The actual destination port number. May differ from the URL's port if overridden, for example 443; 8080.
37+
const KEY_SERVER_PORT: &str = "server.port";
38+
/// The absolute URL of the request, for example https://www.foo.bar/search?q=OpenTelemetry.
39+
const KEY_URL_FULL: &str = "url.full";
40+
/// The URI scheme component identifying the used protocol, for example http; https.
41+
const KEY_URL_SCHEME: &str = "url.scheme";
42+
/// The low-cardinality template of the absolute path, for example /v2/locations/{location}/projects/{project}/.
43+
const KEY_URL_TEMPLATE: &str = "url.template";
44+
/// The nominal domain from the original URL, representing the intended service, for example myservice.googleapis.com.
45+
const KEY_URL_DOMAIN: &str = "url.domain";
46+
47+
/// The numeric HTTP response status code, for example 200; 404; 500.
48+
const KEY_HTTP_RESPONSE_STATUS_CODE: &str = "http.response.status_code";
49+
/// A low cardinality a class of error the operation ended with.
50+
const KEY_ERROR_TYPE: &str = "error.type";
51+
/// The ordinal number of times this request has been resent (e.g., due to retries or redirects). None for the first attempt.
52+
const KEY_HTTP_REQUEST_RESEND_COUNT: &str = "http.request.resend_count";
53+
54+
// Custom GCP Attributes
55+
/// Identifies the Google Cloud service, for example appengine; run; firestore.
56+
const KEY_GCP_CLIENT_SERVICE: &str = "gcp.client.service";
57+
/// The version of the client library, for example v1.0.2.
58+
const KEY_GCP_CLIENT_VERSION: &str = "gcp.client.version";
59+
/// The repository of the client library. Always "googleapis/google-cloud-rust".
60+
const KEY_GCP_CLIENT_REPO: &str = "gcp.client.repo";
61+
/// The crate name of the client library, for example google-cloud-storage.
62+
const KEY_GCP_CLIENT_ARTIFACT: &str = "gcp.client.artifact";
63+
2064
#[derive(Debug, Clone, PartialEq)]
2165
pub(crate) enum OtelStatus {
2266
Unset,
@@ -44,11 +88,11 @@ impl OtelStatus {
4488
#[derive(Debug, Clone)]
4589
pub(crate) struct HttpSpanInfo {
4690
// Attributes for OpenTelemetry SDK interop
47-
/// Span Kind. Always CLIENT for a span representing an outbound HTTP request.
91+
/// Span Kind for OpenTelemetry interop. Always CLIENT for a span representing an outbound HTTP request.
4892
otel_kind: String,
49-
/// Span Name. Recommended to be "{http.request.method} {url.template}" if url.template is available, otherwise "{http.request.method}".
93+
/// Span Name for OpenTelemetry interop. Recommended to be "{http.request.method} {url.template}" if url.template is available, otherwise "{http.request.method}".
5094
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).
95+
/// Span Status for OpenTelemetry interop. 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).
5296
otel_status: OtelStatus,
5397

5498
// OpenTelemetry Semantic Conventions

0 commit comments

Comments
 (0)