Skip to content

Conversation

shimoncohen
Copy link
Contributor

@shimoncohen shimoncohen commented Aug 3, 2025

{{ if .Values.authorization.enabled }}
'"mapcolonies.http.auth.token.client_name":"$jwt_payload_sub",'
'"mapcolonies.http.auth.token.client_name": "$jwt_payload_sub",'
Copy link

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 ?

Comment on lines 21 to 30
map $server_protocol $otel_network_protocol_name {
~^(.+)/.*$ $1;
default "http";
}

map $server_protocol $otel_network_protocol_version {
~^.+/(.+)$ $1;
default "1.1";
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain please?

Copy link
Contributor Author

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.

Copy link

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 ~^.+/(.+)$

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified the regex.

@syncush
Copy link

syncush commented Aug 3, 2025

BTW we have hard coded INFO value, do we custom logs for errors? should we ?

@shimoncohen
Copy link
Contributor Author

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 status code to log levels (warn for 4xx and error for 5xx) with the map directive as with the server_protocol.

@syncush
Copy link

syncush commented Aug 3, 2025

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 status code to log levels (warn for 4xx and error for 5xx) with the map directive as with the server_protocol.

for 5xx we still use INFO ?

@shimoncohen
Copy link
Contributor Author

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 status code to log levels (warn for 4xx and error for 5xx) with the map directive as with the server_protocol.

for 5xx we still use INFO ?

Yes, I just made sure and when we get for example 502 the value of SeverityText is INFO.

Comment on lines 17 to 18
'"http.request.header.content-length": "$content_length",'
'"http.request.body.size": $request_length,'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image image the usage of this nginx variable does not conform to OTEL SPEC

Copy link
Contributor Author

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",'
Copy link
Contributor

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)

Copy link
Contributor Author

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.

'"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,'
Copy link
Contributor

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

Copy link
Contributor Author

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",'
Copy link
Contributor

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)

Copy link
Contributor Author

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",'
Copy link
Contributor

@CptSchnitz CptSchnitz Aug 3, 2025

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@syncush
Copy link

syncush commented Aug 31, 2025

@shimoncohen @netanelC status?

@shimoncohen shimoncohen requested a review from Copilot September 8, 2025 16:53
Copy link

@Copilot Copilot AI left a 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 of network.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",'
Copy link
Preview

Copilot AI Sep 8, 2025

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.

Suggested change
'"server.address": "$server_addr",'
'"server.address": "$host",'

Copilot uses AI. Check for mistakes.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants