Skip to content

Feat/stackittpr 788 context logging - #1704

Draft
cgoetz-inovex wants to merge 6 commits into
mock-refactorfrom
feat/STACKITTPR-788-context-logging
Draft

Feat/stackittpr 788 context logging#1704
cgoetz-inovex wants to merge 6 commits into
mock-refactorfrom
feat/STACKITTPR-788-context-logging

Conversation

@cgoetz-inovex

Copy link
Copy Markdown
Contributor

Description

Proof of concept for removing core.InitProviderCtx and core.LogResponse and related linters.

Based on clientFactory work.

  • adds defaultOptions to each client
  • adds responseLoggingMiddleware to defaultOptions to log the trace-id after each response
  • adds resource, datasource wrappers to pass a context with http response capturing set up into each object
  • adds core.Log* funcs to add x-trace-id from ctx to each log message
  • demos functionality with machine type data source

Testing

   data "stackit_machine_type" "two_vcpus" {
     project_id = var.project_id
     filter     = "vcpus == 2"

     # Optional; defaults to provider.default_region
     region = "eu01"

     # Optional; defaults to false
     sort_ascending = true
   }

   output "machine_type_name" {
     value = data.stackit_machine_type.two_vcpus.name
   }

run TF_LOG=info terraform plan

check that trace ids are present

Next steps

  • wait for clientFactories being merged
  • remove core.InitProviderCtx and core.LogResponse
  • remove corresponding linters
  • add linter to forbid direct tflog.Info|Error|... calls in services

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see examples/ directory)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Acceptance tests got implemented or updated (see e.g. here)
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

additionalFields = append(additionalFields, map[string]interface{}{
"x-trace-id": runtime.GetTraceId(ctx),
})
tflog.Warn(ctx, msg, additionalFields...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess we'll need some linting rule then so only these LogInfo, LogWarn, ... functions are used then, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, I'd add a linter to forbid direct tflog.Info|Error|... calls in the services pkg

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.

2 participants