Skip to content

Use req.host instead of req.headers['host'] on express #1080

@patrick91

Description

@patrick91

Hi, I was trying to improve our tracing to show the correct hostname, we run lambdas under API Gateway with a Cloudfront proxy in front of it, so the host in the header is not the right one, since the right one is in the X-Forwarded-Host header.

You can allow express to trust the X-Forwarded-Host header, see: https://expressjs.com/en/guide/behind-proxies.html

This will set the correct host on req.host, but looks like this is not being used by dd-trace-js[1]. Is there any reason for that?

[1] https://github.com/DataDog/dd-trace-js/blob/master/packages/dd-trace/src/plugins/util/web.js#L415

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions