| 1 |
|
| /* otel_semconv.h - the semantic conventions, pinned. |
| 2 |
|
| * |
| 3 |
|
| * Attribute names are an interface. Dashboards, alerts and saved queries are |
| 4 |
|
| * built on them, so changing one silently is an outage in somebody's |
| 5 |
|
| * observability rather than a rename. They are therefore all in this file, |
| 6 |
|
| * with the convention VERSION beside them, so "which conventions does this |
| 7 |
|
| * speak" has an answer that cannot drift from the code. |
| 8 |
|
| * |
| 9 |
|
| * The HTTP conventions moved recently - http.method became |
| 10 |
|
| * http.request.method, http.status_code became http.response.status_code - |
| 11 |
|
| * and an application whose dashboards were built on one naming does not want |
| 12 |
|
| * the other arriving because it upgraded. Hence the pin. |
| 13 |
|
| * |
| 14 |
|
| * CARDINALITY IS THE THEME. Every attribute here is either bounded by |
| 15 |
|
| * construction or deliberately omitted. An unbounded attribute does not fail |
| 16 |
|
| * loudly; it makes a backend slow and then expensive, and the bill arrives a |
| 17 |
|
| * month after the deploy that caused it. |
| 18 |
|
| */ |
| 19 |
|
| |
| 20 |
|
| #ifndef OTEL_SEMCONV_H |
| 21 |
|
| #define OTEL_SEMCONV_H |
| 22 |
|
| |
| 23 |
|
| /* The convention version these names come from. Emitted as schema_url, so a |
| 24 |
|
| * consumer can tell which vocabulary it is being handed. */ |
| 25 |
|
| #define OTEL_SCHEMA_URL "https://opentelemetry.io/schemas/1.30.0" |
| 26 |
|
| |
| 27 |
|
| /* ---- HTTP server -------------------------------------------------------- */ |
| 28 |
|
| #define SC_HTTP_METHOD "http.request.method" |
| 29 |
|
| #define SC_HTTP_METHOD_ORIGINAL "http.request.method_original" |
| 30 |
|
| #define SC_HTTP_ROUTE "http.route" |
| 31 |
|
| #define SC_HTTP_STATUS "http.response.status_code" |
| 32 |
|
| |
| 33 |
|
| /* The one metric this dist records by itself. SECONDS, which is what the |
| 34 |
|
| * conventions name and what OTEL_DEFAULT_BOUNDS is built for - a histogram of |
| 35 |
|
| * milliseconds against those boundaries puts every web request in the last |
| 36 |
|
| * bucket. */ |
| 37 |
|
| #define SC_HTTP_SERVER_DURATION "http.server.request.duration" |
| 38 |
|
| #define SC_URL_PATH "url.path" |
| 39 |
|
| #define SC_URL_SCHEME "url.scheme" |
| 40 |
|
| #define SC_URL_QUERY "url.query" |
| 41 |
|
| #define SC_SERVER_ADDRESS "server.address" |
| 42 |
|
| #define SC_SERVER_PORT "server.port" |
| 43 |
|
| #define SC_CLIENT_ADDRESS "client.address" |
| 44 |
|
| #define SC_USER_AGENT "user_agent.original" |
| 45 |
|
| #define SC_NETWORK_PROTOCOL "network.protocol.version" |
| 46 |
|
| #define SC_ERROR_TYPE "error.type" |
| 47 |
|
| |
| 48 |
|
| /* ---- HTTP client -------------------------------------------------------- */ |
| 49 |
|
| #define SC_URL_FULL "url.full" |
| 50 |
|
| |
| 51 |
|
| /* ---- database ----------------------------------------------------------- */ |
| 52 |
|
| #define SC_DB_SYSTEM "db.system.name" |
| 53 |
|
| #define SC_DB_NAMESPACE "db.namespace" |
| 54 |
|
| #define SC_DB_OPERATION "db.operation.name" |
| 55 |
|
| #define SC_DB_QUERY_TEXT "db.query.text" |
| 56 |
|
| #define SC_DB_COLLECTION "db.collection.name" |
| 57 |
|
| |
| 58 |
|
| /* ---- messaging ---------------------------------------------------------- */ |
| 59 |
|
| #define SC_MSG_SYSTEM "messaging.system" |
| 60 |
|
| #define SC_MSG_DESTINATION "messaging.destination.name" |
| 61 |
|
| #define SC_MSG_OPERATION "messaging.operation.type" |
| 62 |
|
| #define SC_MSG_MESSAGE_ID "messaging.message.id" |
| 63 |
|
| |
| 64 |
|
| /* ---- rpc / graphql ------------------------------------------------------ */ |
| 65 |
|
| #define SC_GRAPHQL_OPERATION "graphql.operation.name" |
| 66 |
|
| #define SC_GRAPHQL_TYPE "graphql.operation.type" |
| 67 |
|
| |
| 68 |
|
| /* The HTTP methods the conventions know. |
| 69 |
|
| * |
| 70 |
|
| * ANYTHING ELSE BECOMES "_OTHER", with the raw value in |
| 71 |
|
| * http.request.method_original. The method is client-controlled and otherwise |
| 72 |
|
| * unbounded - a scanner sending a thousand invented verbs would otherwise |
| 73 |
|
| * create a thousand values of a metric dimension - and this attribute lands |
| 74 |
|
| * in exactly such a dimension in the metrics phase. Normalising here means |
| 75 |
|
| * nobody has to remember to do it there. */ |
| 76 |
|
| static const char *const SC_KNOWN_METHODS[] = { |
| 77 |
|
| "CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", |
| 78 |
|
| "PATCH", "POST", "PUT", "TRACE", NULL |
| 79 |
|
| }; |
| 80 |
|
| |
| 81 |
|
| /* Returns the canonical method, or NULL when it is not a known one - in which |
| 82 |
|
| * case the caller emits "_OTHER" and keeps the original separately. */ |
| 83 |
30 |
| static const char *otel_sc_method(const char *m, STRLEN len) { |
| 84 |
|
| int i; |
| 85 |
30 |
▶ | if (!m || !len || len > 16) return NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!m || !len || len > 16) return NULL; |
30 |
0 |
30 |
| if (!m || !len || len > 16) return NULL; |
29 |
1 |
30 |
| if (!m || !len || len > 16) return NULL; |
1 |
28 |
29 |
|
| 86 |
123 |
▶ | for (i = 0; SC_KNOWN_METHODS[i]; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; SC_KNOWN_METHODS[i]; i++) { |
120 |
3 |
123 |
|
| 87 |
120 |
▶ | if (strlen(SC_KNOWN_METHODS[i]) == len |
Branch: 1 branch
| Branch | True | False | Total |
| if (strlen(SC_KNOWN_METHODS[i]) == len |
31 |
89 |
120 |
|
| 88 |
31 |
▶ | && memEQ(m, SC_KNOWN_METHODS[i], len)) |
Branch: 1 branch
| Branch | True | False | Total |
| && memEQ(m, SC_KNOWN_METHODS[i], len)) |
25 |
6 |
31 |
|
| 89 |
25 |
| return SC_KNOWN_METHODS[i]; |
| 90 |
|
| } |
| 91 |
3 |
| return NULL; |
| 92 |
|
| } |
| 93 |
|
| |
| 94 |
|
| /* The span status implied by an HTTP status, for a SERVER span. |
| 95 |
|
| * |
| 96 |
|
| * 4xx is NOT an error on the server side. A 404 or a 401 is the server |
| 97 |
|
| * working correctly and saying no; marking those as errors makes the error |
| 98 |
|
| * rate a measure of how many people mistyped a URL, which is a graph nobody |
| 99 |
|
| * can act on. 5xx is an error. Everything else is left UNSET, because an |
| 100 |
|
| * instrumentation layer with no opinion must not claim one. */ |
| 101 |
15 |
| static int otel_sc_server_status(IV http_status) { |
| 102 |
15 |
▶ | if (http_status >= 500) return OTEL_STATUS_ERROR; |
Branch: 1 branch
| Branch | True | False | Total |
| if (http_status >= 500) return OTEL_STATUS_ERROR; |
7 |
8 |
15 |
|
| 103 |
8 |
| return OTEL_STATUS_UNSET; |
| 104 |
|
| } |
| 105 |
|
| |
| 106 |
|
| /* For a CLIENT span the rule differs, and deliberately: a 4xx the client |
| 107 |
|
| * received IS a failure of the call the client made. */ |
| 108 |
4 |
| static int otel_sc_client_status(IV http_status) { |
| 109 |
4 |
▶ | if (http_status >= 400) return OTEL_STATUS_ERROR; |
Branch: 1 branch
| Branch | True | False | Total |
| if (http_status >= 400) return OTEL_STATUS_ERROR; |
2 |
2 |
4 |
|
| 110 |
2 |
| return OTEL_STATUS_UNSET; |
| 111 |
|
| } |
| 112 |
|
| |
| 113 |
|
| /* The leading keyword of a statement, uppercased, as db.operation.name - |
| 114 |
|
| * SELECT, INSERT, UPDATE. Bounded to a short buffer, so a pathological |
| 115 |
|
| * statement cannot make this allocate. Returns 0 when there is no sane |
| 116 |
|
| * keyword to report. */ |
| 117 |
11 |
| static int otel_sc_db_operation(const char *sql, STRLEN len, char *out, |
| 118 |
|
| STRLEN cap) { |
| 119 |
11 |
| STRLEN i = 0, o = 0; |
| 120 |
11 |
▶ | if (!sql || !len || cap < 2) return 0; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!sql || !len || cap < 2) return 0; |
11 |
0 |
11 |
| if (!sql || !len || cap < 2) return 0; |
10 |
1 |
11 |
| if (!sql || !len || cap < 2) return 0; |
0 |
10 |
10 |
|
| 121 |
16 |
▶ | while (i < len && (sql[i] == ' ' || sql[i] == '\t' || sql[i] == '\n' |
Branch: 4 branches
| Branch | True | False | Total |
| while (i < len && (sql[i] == ' ' || sql[i] == '\t' || sql[i] == '\n' |
16 |
0 |
16 |
| while (i < len && (sql[i] == ' ' || sql[i] == '\t' || sql[i] == '\n' |
3 |
13 |
16 |
| while (i < len && (sql[i] == ' ' || sql[i] == '\t' || sql[i] == '\n' |
1 |
12 |
13 |
| while (i < len && (sql[i] == ' ' || sql[i] == '\t' || sql[i] == '\n' |
1 |
11 |
12 |
|
| 122 |
16 |
▶ | || sql[i] == '\r' || sql[i] == '(')) i++; |
Branch: 2 branches
| Branch | True | False | Total |
| || sql[i] == '\r' || sql[i] == '(')) i++; |
0 |
11 |
11 |
| || sql[i] == '\r' || sql[i] == '(')) i++; |
1 |
10 |
11 |
|
| 123 |
89 |
▶ | while (i < len && o + 1 < cap) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (i < len && o + 1 < cap) { |
89 |
0 |
89 |
| while (i < len && o + 1 < cap) { |
88 |
1 |
89 |
|
| 124 |
88 |
| char c = sql[i]; |
| 125 |
88 |
▶ | if (c >= 'a' && c <= 'z') c = (char)(c - 'a' + 'A'); |
Branch: 2 branches
| Branch | True | False | Total |
| if (c >= 'a' && c <= 'z') c = (char)(c - 'a' + 'A'); |
6 |
82 |
88 |
| if (c >= 'a' && c <= 'z') c = (char)(c - 'a' + 'A'); |
6 |
0 |
6 |
|
| 126 |
88 |
▶ | if (!(c >= 'A' && c <= 'Z')) break; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(c >= 'A' && c <= 'Z')) break; |
79 |
9 |
88 |
| if (!(c >= 'A' && c <= 'Z')) break; |
79 |
0 |
79 |
|
| 127 |
79 |
| out[o++] = c; |
| 128 |
79 |
| i++; |
| 129 |
|
| } |
| 130 |
10 |
| out[o] = '\0'; |
| 131 |
10 |
| return o > 0; |
| 132 |
|
| } |
| 133 |
|
| |
| 134 |
|
| #endif /* OTEL_SEMCONV_H */ |