Skip to content

misc: expose reusable logging functions#207

Merged
hgiasac merged 1 commit into
mainfrom
expose-log-exporter
Sep 28, 2025
Merged

misc: expose reusable logging functions#207
hgiasac merged 1 commit into
mainfrom
expose-log-exporter

Conversation

@hgiasac
Copy link
Copy Markdown
Collaborator

@hgiasac hgiasac commented Sep 28, 2025

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:

  • Introduced NewContextLogger and NewJSONLogger helper functions in logger.go to standardize logger creation and context injection, replacing custom logic and removing the old initLogger function. (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))
  • Replaced all usages of the previous logContextKey and direct context manipulation with the new loggerContextKey and NewContextLogger for 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:

  • Enhanced the getRequestID function 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:

  • Removed unused imports (os, strings, and context) 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))
  • Removed the obsolete serverContextKey and logContextKey definitions from http.go. (F823ecd0L23R23)

Minor telemetry improvement:

  • Updated resource attribute gathering in telemetry setup to include environment attributes for more complete OpenTelemetry resource information. ([[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))

@github-actions
Copy link
Copy Markdown

Code Coverage

Package Line Rate Health
github.com/hasura/ndc-codegen-example 98%
github.com/hasura/ndc-codegen-example/functions 63%
github.com/hasura/ndc-codegen-example/types/arguments 43%
github.com/hasura/ndc-codegen-example/types 32%
github.com/hasura/ndc-sdk-go/v2/cmd/hasura-ndc-go/command/internal 84%
github.com/hasura/ndc-sdk-go/v2/cmd/hasura-ndc-go/command 46%
github.com/hasura/ndc-sdk-go/v2/cmd/hasura-ndc-go/version 62%
github.com/hasura/ndc-sdk-go/v2/connector 59%
github.com/hasura/ndc-sdk-go/v2/credentials 75%
github.com/hasura/ndc-sdk-go/v2/example/reference 54%
github.com/hasura/ndc-sdk-go/v2/ndctest 68%
github.com/hasura/ndc-sdk-go/v2/scalar 90%
github.com/hasura/ndc-sdk-go/v2/schema 23%
github.com/hasura/ndc-sdk-go/v2/utils/compression 67%
github.com/hasura/ndc-sdk-go/v2/utils 53%
Summary 46% (12487 / 26918)

Minimum allowed line rate is 40%

@hgiasac hgiasac merged commit 12bb41e into main Sep 28, 2025
2 checks passed
@hgiasac hgiasac deleted the expose-log-exporter branch September 28, 2025 07:53
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.

1 participant