Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http.request.id not working #129

Closed
diegoneemu opened this issue Sep 30, 2022 · 1 comment
Closed

http.request.id not working #129

diegoneemu opened this issue Sep 30, 2022 · 1 comment
Labels
agent-nodejs Make available for APM Agents project planning. community triage

Comments

@diegoneemu
Copy link

Hello everybody

I'm having trouble getting the http.request.id to log in correctly. Looking at the lib @elastic/ecs-winston-format
and @elastic/ecs-helpers
, I couldn't find any parse of the X-Request-ID or X-Correlation-ID headers as it says in the documentation and in our observability stack we couldn't get our logs to index the field in question. Is this already on the radar or planned for some version? If not, how can I contribute so that it can enter a future version?

I noticed that there are two issues already open on the subject, http.request.id field from ECS 1.9 and event.id -> http.request.id in formatHttpRequest, but I couldn't understand if the implementation was carried out.

Sorry for the bad English.

Imported packages from npm:

"@elastic/ecs-winston-format": "^1.3.1"
"winston": "3.2.1"

Header example:

headers: {
  'x-request-id': '00162b9b-3083-40b4-8b87-42636efcc651#19974',
  'content-type': 'application/json',
  'user-agent': 'PostmanRuntime/7.29.2',
  accept: '*/*',
  'postman-token': '6d3538e6-063d-4a7d-bd9a-604ed555a920',
  host: 'localhost:3001',
  'accept-encoding': 'gzip, deflate, br',
  connection: 'keep-alive',
  'content-length': '7656'
}

Create logger using winston and @elastic/ecs-winston-format

import { createLogger, Logger, transports } from 'winston'
import ecsFormat from '@elastic/ecs-winston-format'

const logger = createLogger({
  format: ecsFormat({ convertReqRes: true }),
  transports: [new transports.Console()],
  silent: process.env.NODE_ENV === 'test',
})

export default logger

Inject logger in a express request middleware for using in other middlewares and services

import logger from './logger'

...

// implementing a express app

...

app.use((req, res, next) => {
  logger.child({ req })
  req.logger = logger;
  next();
})

// use logger in a route
app.delete('/path', (req, res) => {
  const { logger } = req;

  logger.info({"Send request to api"});
})

Resulting log:

{
  "@timestamp": "2022-09-30T13:58:00.115Z",
  "log.level": "info",
  "message": "Send request to api",
  "ecs": {
    "version": "1.6.0"
  },
  "http": {
    "version": "1.1",
    "request": {
      "method": "DELETE",
      "headers": {
        "x-request-id": "00162b9b-3083-40b4-8b87-42636efcc651#19974",
        "content-type": "application/json",
        "user-agent": "PostmanRuntime/7.29.2",
        "accept": "*/*",
        "postman-token": "95bfc606-74af-43eb-9f60-05c02ec0b3ed",
        "host": "localhost:3001",
        "accept-encoding": "gzip, deflate, br",
        "connection": "keep-alive",
        "content-length": "7656"
      },
      "body": {
        "bytes": 7656
      }
    }
  },
  "url": {
    "path": "/path",
    "query": "foo=bar&fooz=barz",
    "full": "http://localhost:3001/path?foo=bar&fooz=barz"
  },
  "client": {
    "address": "::1",
    "ip": "::1",
    "port": 52527
  },
  "user_agent": {
    "original": "PostmanRuntime/7.29.2"
  }
}
@github-actions github-actions bot added agent-nodejs Make available for APM Agents project planning. community triage labels Sep 30, 2022
@trentm
Copy link
Member

trentm commented Oct 26, 2023

@diegoneemu Thanks very much for the issue! My apologies for not having responded sooner. The http.request.id field had not yet been implemented, which is why it wasn't showing up for you. I've now opened a PR to do that, so within a week or so there will be a release with this functionality.

I'm closing this issue in favour of #76 (duplicate).

@trentm trentm closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning. community triage
Projects
None yet
Development

No branches or pull requests

2 participants