-
Notifications
You must be signed in to change notification settings - Fork 0
fix: log format doesn't uphold opentelemetry field naming (MAPCO-8460) #17
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
base: master
Are you sure you want to change the base?
Conversation
{{ if .Values.authorization.enabled }} | ||
'"mapcolonies.http.auth.token.client_name":"$jwt_payload_sub",' | ||
'"mapcolonies.http.auth.token.client_name": "$jwt_payload_sub",' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CptSchnitz , back in the days we tried to put mapcolonies custom fields under "mapcolonies" key, do you think we should put it in the body or message key ?
helm/config/nginx.conf
Outdated
map $server_protocol $otel_network_protocol_name { | ||
~^(.+)/.*$ $1; | ||
default "http"; | ||
} | ||
|
||
map $server_protocol $otel_network_protocol_version { | ||
~^.+/(.+)$ $1; | ||
default "1.1"; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opentelemetry doesn't have a field for the nginx
server_protocol
variable and we cannot get the network.protocol.name
or network.protocol.version
(https://opentelemetry.io/docs/specs/semconv/registry/attributes/network/) from any nginx variable
.
What we are doing here is "splitting" the server_protocol
variable by the /
to get the name and version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes i didnt understand the dark magic of ~^.+/(.+)$
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simplified the regex.
BTW we have hard coded INFO value, do we custom logs for errors? should we ? |
If I understood you correctly, we can map logs based on the |
for 5xx we still use INFO ? |
Yes, I just made sure and when we get for example |
helm/config/log_format.conf
Outdated
'"http.request.header.content-length": "$content_length",' | ||
'"http.request.body.size": $request_length,' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think I should change it to use "$content_length"
as well?
'"mapcolonies.http.upstream_bytes_sent": $upstream_bytes_sent,' | ||
'"mapcolonies.http.upstream_bytes_received": $upstream_bytes_received,' | ||
'"mapcolonies.http.upstream_cache_status": "$upstream_cache_status",' | ||
'"host.name": "$hostname",' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$hostname in nginx is for the server name (in the SERVER block)
host.name in otel is for the machine host name (not under attributes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the documentation:
Name of the host. On Unix systems, it may contain what the hostname command returns, or the fully qualified hostname, or another name specified by the user.
It seems that this is the recieved value from $hostname
.
helm/config/log_format.conf
Outdated
'"mapcolonies.http.upstream_status_code": "$upstream_status",' | ||
'"mapcolonies.http.upstream_connect_time": "$upstream_connect_time",' | ||
'"mapcolonies.http.upstream_response_time": "$upstream_response_time",' | ||
'"mapcolonies.http.upstream_response_length": $upstream_response_length,' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if the upstream returns 204? i remember it doesnt return a value and then the json is broken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll put it in quotes.
'"http.response.header.x_forwarded_for": "$proxy_add_x_forwarded_for",' | ||
'"http.response.status_code": "$status",' | ||
'"user_agent.original": "$http_user_agent",' | ||
'"network.protocol.name": "$otel_network_protocol_name",' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not required according to the docs if its http (pretty sure its always http in our case)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, but it won't hurt.
'"url.path":"$uri",' | ||
'"url.full":"$request_uri"' | ||
'"http.request.method": "$request_method",' | ||
'"http.request.header.host": "$host",' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to the docs it should be in server address
https://opentelemetry.io/docs/specs/semconv/http/http-spans/#setting-serveraddress-and-serverport-attributes
we need to make sure if theres a value for both
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like "$hostname"
fits the server.address
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The host
variable (from nginx):
in this order of precedence: host name from the request line, or host name from the “Host” request header field, or the server name matching a request
@shimoncohen @netanelC status? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the nginx log format configuration to align with OpenTelemetry field naming conventions. The changes ensure that logged HTTP metrics and network protocol information follow the standardized OpenTelemetry semantic conventions for better observability and compatibility.
- Adds network protocol extraction maps to parse protocol name and version from
$server_protocol
- Updates log field names to match OpenTelemetry semantic conventions (e.g.,
network.protocol.name
instead ofnetwork.protocol
) - Enhances request/response logging with additional OpenTelemetry-compliant fields
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
helm/config/nginx.conf | Adds map directives to extract protocol name and version from server protocol |
helm/config/log_format.conf | Updates field names and values to comply with OpenTelemetry semantic conventions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
'"mapcolonies.http.upstream_bytes_received": $upstream_bytes_received,' | ||
'"mapcolonies.http.upstream_cache_status": "$upstream_cache_status",' | ||
'"host.name": "$hostname",' | ||
'"server.address": "$server_addr",' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to OpenTelemetry semantic conventions, server.address
should represent the logical server hostname/address that the client is connecting to, not the physical server IP. This should likely use $host
or $server_name
instead of $server_addr
.
'"server.address": "$server_addr",' | |
'"server.address": "$host",' |
Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Additional read:
https://nginx.org/en/docs/http/ngx_http_core_module.html
https://www.dash0.com/documentation/dash0/logging/nginx-logs#extracted-semantic-attributes