Skip to content

feat(httpjson): Add structured logging for non-200 HTTP errors#45653

Merged
andrewkroh merged 2 commits intoelastic:mainfrom
andrewkroh:filebeat/feat/httpjson-http-code
Jul 31, 2025
Merged

feat(httpjson): Add structured logging for non-200 HTTP errors#45653
andrewkroh merged 2 commits intoelastic:mainfrom
andrewkroh:filebeat/feat/httpjson-http-code

Conversation

@andrewkroh
Copy link
Member

Proposed commit message

Add structured metadata to HTTP error logs in httpjson input to enable filtering and analysis similar to CEL logs. This change:

  • Adds httpError struct to capture HTTP status code, message, and body
  • Replaces Errorf logging with Errorw structured logging that includes:
    • error.code: HTTP status code
    • error.id: HTTP status message (e.g. 400 Bad Request)
    • error.type: "http"
    • error.message

Relates #45254

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Disruptive User Impact

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

Example output:

{
  "log.level": "error",
  "@timestamp": "2025-07-30T16:23:50.392-0400",
  "log.logger": "httpjson_test",
  "log.origin": {
    "function": "github.com/elastic/beats/v7/x-pack/filebeat/input/httpjson.run.func1",
    "file.name": "httpjson/input.go",
    "file.line": 250
  },
  "message": "Error while processing http request",
  "input_url": "http://127.0.0.1:56950",
  "error": {
    "message": "failed to collect first response: failed to execute http POST: server responded with status code 400 Bad Request: {\"error\":\"expected method was \"GET\"\"}"
  },
  "error.code": 400,
  "error.id": "400 Bad Request",
  "error.type": "http",
  "ecs.version": "1.6.0"
}
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jul 30, 2025
@github-actions
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@mergify
Copy link
Contributor

mergify bot commented Jul 30, 2025

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @andrewkroh? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.
Add structured metadata to HTTP error logs in httpjson input to enable
filtering and analysis similar to CEL logs. This change:

- Introduces httpError struct to capture HTTP status code, message, and body
- Replaces Errorf logging with Errorw structured logging that includes:
  - error.code: HTTP status code
  - error.id: HTTP status message (e.g. 400 Bad Request)
  - error.type: "http"
  - error.message

Relates to elastic#45254
@andrewkroh andrewkroh force-pushed the filebeat/feat/httpjson-http-code branch from bd11a62 to 9fcc6cc Compare July 30, 2025 20:44
@andrewkroh andrewkroh added Filebeat Filebeat Team:Security-Service Integrations Security Service Integrations Team labels Jul 30, 2025
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jul 30, 2025
@andrewkroh andrewkroh added needs_team Indicates that the issue/PR needs a Team:* label backport-active-9 Automated backport with mergify to all the active 9.[0-9]+ branches labels Jul 30, 2025
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jul 30, 2025
@andrewkroh andrewkroh added needs_team Indicates that the issue/PR needs a Team:* label backport-8.19 Automated backport to the 8.19 branch labels Jul 30, 2025
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jul 30, 2025
@andrewkroh andrewkroh marked this pull request as ready for review July 31, 2025 02:28
@andrewkroh andrewkroh requested a review from a team as a code owner July 31, 2025 02:28
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-service-integrations (Team:Security-Service Integrations)

@mergify
Copy link
Contributor

mergify bot commented Jul 31, 2025

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b filebeat/feat/httpjson-http-code upstream/filebeat/feat/httpjson-http-code
git merge upstream/main
git push upstream filebeat/feat/httpjson-http-code
@andrewkroh andrewkroh enabled auto-merge (squash) July 31, 2025 03:06
@andrewkroh andrewkroh merged commit 0db1bc6 into elastic:main Jul 31, 2025
33 of 36 checks passed
@github-actions
Copy link
Contributor

@Mergifyio backport 9.0 9.1

@mergify
Copy link
Contributor

mergify bot commented Jul 31, 2025

backport 9.0 9.1

✅ Backports have been created

Details
mergify bot pushed a commit that referenced this pull request Jul 31, 2025
Add structured metadata to HTTP error logs in httpjson input to enable
filtering and analysis similar to CEL logs. This change:

- Introduces httpError struct to capture HTTP status code, message, and body
- Replaces Errorf logging with Errorw structured logging that includes:
  - error.code: HTTP status code
  - error.id: HTTP status message (e.g. 400 Bad Request)
  - error.type: "http"
  - error.message

Relates to #45254

(cherry picked from commit 0db1bc6)
mergify bot pushed a commit that referenced this pull request Jul 31, 2025
Add structured metadata to HTTP error logs in httpjson input to enable
filtering and analysis similar to CEL logs. This change:

- Introduces httpError struct to capture HTTP status code, message, and body
- Replaces Errorf logging with Errorw structured logging that includes:
  - error.code: HTTP status code
  - error.id: HTTP status message (e.g. 400 Bad Request)
  - error.type: "http"
  - error.message

Relates to #45254

(cherry picked from commit 0db1bc6)
mergify bot pushed a commit that referenced this pull request Jul 31, 2025
Add structured metadata to HTTP error logs in httpjson input to enable
filtering and analysis similar to CEL logs. This change:

- Introduces httpError struct to capture HTTP status code, message, and body
- Replaces Errorf logging with Errorw structured logging that includes:
  - error.code: HTTP status code
  - error.id: HTTP status message (e.g. 400 Bad Request)
  - error.type: "http"
  - error.message

Relates to #45254

(cherry picked from commit 0db1bc6)
andrewkroh added a commit that referenced this pull request Aug 4, 2025
…-200 HTTP errors (#45656)

Add structured metadata to HTTP error logs in httpjson input to enable
filtering and analysis similar to CEL logs. This change:

- Introduces httpError struct to capture HTTP status code, message, and body
- Replaces Errorf logging with Errorw structured logging that includes:
  - error.code: HTTP status code
  - error.id: HTTP status message (e.g. 400 Bad Request)
  - error.type: "http"
  - error.message

Relates to #45254

(cherry picked from commit 0db1bc6)

---------

Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>
andrewkroh added a commit that referenced this pull request Aug 4, 2025
…-200 HTTP errors (#45657)

Add structured metadata to HTTP error logs in httpjson input to enable
filtering and analysis similar to CEL logs. This change:

- Introduces httpError struct to capture HTTP status code, message, and body
- Replaces Errorf logging with Errorw structured logging that includes:
  - error.code: HTTP status code
  - error.id: HTTP status message (e.g. 400 Bad Request)
  - error.type: "http"
  - error.message

Relates to #45254

(cherry picked from commit 0db1bc6)

---------

Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>
andrewkroh added a commit that referenced this pull request Aug 4, 2025
…n-200 HTTP errors (#45658)

Add structured metadata to HTTP error logs in httpjson input to enable
filtering and analysis similar to CEL logs. This change:

- Introduces httpError struct to capture HTTP status code, message, and body
- Replaces Errorf logging with Errorw structured logging that includes:
  - error.code: HTTP status code
  - error.id: HTTP status message (e.g. 400 Bad Request)
  - error.type: "http"
  - error.message

Relates to #45254

(cherry picked from commit 0db1bc6)

---------

Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-8.19 Automated backport to the 8.19 branch backport-active-9 Automated backport with mergify to all the active 9.[0-9]+ branches Filebeat Filebeat Team:Security-Service Integrations Security Service Integrations Team

3 participants