Add structured logs to zenml-server using structlog#4676
Open
amitvikramraj wants to merge 14 commits intodevelopfrom
Open
Add structured logs to zenml-server using structlog#4676amitvikramraj wants to merge 14 commits intodevelopfrom
amitvikramraj wants to merge 14 commits intodevelopfrom
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
1 task
docker/zenml-server-dev.Dockerfile
Outdated
| && uv pip install .[server,secrets-aws,secrets-gcp,secrets-azure,secrets-hashicorp,s3fs,gcsfs,adlfs,connectors-aws,connectors-gcp,connectors-azure,azureml,sagemaker,vertex] "alembic==1.15.2" \ | ||
| && uv pip uninstall zenml \ | ||
| && uv pip freeze > requirements.txt | ||
| && uv pip install .[server,secrets-aws,secrets-gcp,secrets-azure,secrets-hashicorp,s3fs,gcsfs,adlfs,connectors-aws,connectors-gcp,connectors-azure,azureml,sagemaker,vertex,otel] "alembic==1.15.2" \ |
Contributor
There was a problem hiding this comment.
I am thinking otel might as well be part of the server dependencies.
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.
Changes I made
ConsoleFormatterwith structlog as aProcessorFormatterover Python's standard logging.zen_server/,zen_stores/) now emit structured events with keyword arguments instead of f-string messages.request_id,method,path, etc.) is automatically propagated via structlog contextvars — no manual interpolation needed.X-Request-IDin error responses to easily be able to filter logsWhy
structlogprovides parseable JSON output in the server and colored console output locally, with automatic context propagation.Before / After
Before:
After — console:
After — JSON (server default, queryable in Loki/Grafana):
{"event":"request.received","level":"debug","logger":"zenml.zen_server.middleware","method":"GET","path":"/api/v1/pipelines","request_id":"d5638eeb","client_ip":"172.217.26.123","timestamp":"2026-04-02T09:21:52Z"} {"event":"sql.session.started","level":"debug","logger":"zenml.zen_stores.sql_zen_store","caller":"SqlZenStore.list_runs","active_connections":0,"idle_connections":3,"request_id":"d5638eeb","timestamp":"2026-04-02T09:21:52Z"} {"event":"sql.session.completed","level":"debug","logger":"zenml.zen_stores.sql_zen_store","caller":"SqlZenStore.list_runs","duration_ms":12.34,"error":false,"request_id":"d5638eeb","timestamp":"2026-04-02T09:21:52Z"} {"event":"request.completed","level":"debug","logger":"zenml.zen_server.middleware","method":"GET","path":"/api/v1/pipelines","status_code":200,"duration_ms":"38.42ms","request_id":"d5638eeb","timestamp":"2026-04-02T09:21:52Z"}Steps to reproduce:
docker compose up --build— ZenML UI starts on port3001, Grafana UI runs on port3002TODO: Later remove the docker-compose.