Skip to content

feat: Log environment IDs in SDK endpoints#5365

Merged
khvn26 merged 3 commits intomainfrom
feat/log-environment-ids
Apr 22, 2025
Merged

feat: Log environment IDs in SDK endpoints#5365
khvn26 merged 3 commits intomainfrom
feat/log-environment-ids

Conversation

@khvn26
Copy link
Copy Markdown
Member

@khvn26 khvn26 commented Apr 21, 2025

Thanks for submitting a PR! Please check the boxes below:

  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

In this PR, we use functionality added by Flagsmith/flagsmith-common#55 to log environment IDs in SDK endpoints.

The resolved environment ID can be aded by adding %{flagsmith.environment_id}e to ACCESS_LOG_FORMAT, or setting ACCESS_LOG_JSON_EXTRA_ITEMS to "{flagsmith.environment_id}e" for surfacing it in JSON access logs.

How did you test this code?

Ran Core API locally and curl localhost:8000/api/v1/environment-document/ -H 'X-Environment-Key: <locally created server API key>':

ACCESS_LOG_EXTRA_ITEMS='{flagsmith.environment_id}e' LOG_FORMAT=json ACCESS_LOG_LOCATION=- make serve
poetry run flagsmith start --reload api
{"levelname": "INFO", "message": "Starting gunicorn 23.0.0", "timestamp": "2025-04-21 22:02:12,436", "logger_name": "gunicorn.error", "pid": 17755, "thread_name": "MainThread"}
{"levelname": "INFO", "message": "Listening at: http://0.0.0.0:8000 (17755)", "timestamp": "2025-04-21 22:02:12,436", "logger_name": "gunicorn.error", "pid": 17755, "thread_name": "MainThread"}
{"levelname": "INFO", "message": "Using worker: sync", "timestamp": "2025-04-21 22:02:12,436", "logger_name": "gunicorn.error", "pid": 17755, "thread_name": "MainThread"}
{"levelname": "INFO", "message": "Booting worker with pid: 18117", "timestamp": "2025-04-21 22:02:12,443", "logger_name": "gunicorn.error", "pid": 18117, "thread_name": "MainThread"}
{"levelname": "INFO", "message": "127.0.0.1 - - [21/Apr/2025:22:02:16 +0000] \"GET /api/v1/environment-document/ HTTP/1.1\" 200 805 \"-\" \"curl/8.7.1\" - -", "timestamp": "2025-04-21 22:02:16,961", "logger_name": "gunicorn.access", "pid": 18117, "thread_name": "MainThread", "time": "2025-04-21T22:02:16+00:00", "path": "/api/v1/environment-document/", "remote_ip": "127.0.0.1", "route": "/api/v1/environment-document/", "method": "GET", "status": "200", "user_agent": "curl/8.7.1", "duration_in_ms": 56, "response_size_in_bytes": 805, "environ_variables": {"flagsmith.environment_id": 1}}

@khvn26 khvn26 requested a review from a team as a code owner April 21, 2025 19:10
@khvn26 khvn26 requested review from matthewelwell and removed request for a team April 21, 2025 19:10
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Apr 22, 2025 9:00am
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview Apr 22, 2025 9:00am
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview Apr 22, 2025 9:00am

@github-actions github-actions bot added api Issue related to the REST API feature New feature or request labels Apr 21, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 21, 2025

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-5365 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-5365 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-5365 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api-test:pr-5365 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith:pr-5365 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-5365 Finished ✅ Results

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 21, 2025

Uffizzi Preview deployment-62993 was deleted.

@khvn26 khvn26 force-pushed the feat/log-environment-ids branch from 46264d4 to c614d51 Compare April 21, 2025 19:13
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Apr 21, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.61%. Comparing base (4b0ae75) to head (50b5e83).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5365   +/-   ##
=======================================
  Coverage   97.61%   97.61%           
=======================================
  Files        1237     1237           
  Lines       42971    42974    +3     
=======================================
+ Hits        41948    41951    +3     
  Misses       1023     1023           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Apr 22, 2025
@khvn26 khvn26 merged commit ea21668 into main Apr 22, 2025
37 checks passed
@khvn26 khvn26 deleted the feat/log-environment-ids branch April 22, 2025 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants