misc: expose reusable logging functions#207
Merged
Merged
Conversation
Minimum allowed line rate is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors how loggers are created, injected, and retrieved from context throughout the connector codebase. The changes centralize logger context handling, improve logger initialization, and enhance request ID generation for better traceability. Key updates include removing duplicated logger code, introducing helper functions for context and logger creation, and improving how request IDs are determined.
Logger context management and initialization:
NewContextLoggerandNewJSONLoggerhelper functions inlogger.goto standardize logger creation and context injection, replacing custom logic and removing the oldinitLoggerfunction. (F055989eL15R15,F055989eL155R155,[[1]](https://github.com/hasura/ndc-sdk-go/pull/207/files#diff-e11f4a70ce3453d64ce4799174ff9740fde5fd7fa03b9ebee3116adf80819e70L71-R75),[[2]](https://github.com/hasura/ndc-sdk-go/pull/207/files#diff-e11f4a70ce3453d64ce4799174ff9740fde5fd7fa03b9ebee3116adf80819e70L92-L112))logContextKeyand direct context manipulation with the newloggerContextKeyandNewContextLoggerfor consistent logger propagation. (F055989eL146R146,[connector/server.goL130-R130](https://github.com/hasura/ndc-sdk-go/pull/207/files#diff-83302262c5bae5edff30c79b5c66523a44fbf1435e957341aab5a68306140546L130-R130),F823ecd0L232R232)Request ID and tracing improvements:
getRequestIDfunction to prefer the HTTP header, then use the trace ID from the OpenTelemetry span, and finally fall back to a generated UUID, improving request traceability. (F823ecd0L321R321,F823ecd0L112R112)Code cleanup and dependency management:
os,strings, andcontext) from files now using centralized logger helpers. ([[1]](https://github.com/hasura/ndc-sdk-go/pull/207/files#diff-e11f4a70ce3453d64ce4799174ff9740fde5fd7fa03b9ebee3116adf80819e70L7-L8),[[2]](https://github.com/hasura/ndc-sdk-go/pull/207/files#diff-7456e9f6044d6088e014ed4672d950d8d0d4bf054e8be927eb6ec76aef1c44feL5))serverContextKeyandlogContextKeydefinitions fromhttp.go. (F823ecd0L23R23)Minor telemetry improvement:
[[1]](https://github.com/hasura/ndc-sdk-go/pull/207/files#diff-5a289d8977f52b8f78b3c6e86385a4b6544a07440f869c477d5f49ddece84bdcL379-R380),[[2]](https://github.com/hasura/ndc-sdk-go/pull/207/files#diff-5a289d8977f52b8f78b3c6e86385a4b6544a07440f869c477d5f49ddece84bdcR389-R390))