FAQ
I'm looking for a way to establish what IP address a golang http client
tried to establish an http connection to when making a request, in order to
add extra information to logs (particularly for debugging CDNs with global
edge servers and geoDNS etc). Obviously this information is needed for both
the errors and completed responses.

Is this information already there, or is there an elegant route to adding
it?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Giulio Iotti at Sep 9, 2015 at 7:49 pm

    On Wednesday, September 9, 2015 at 10:21:32 PM UTC+3, Daniel Speed wrote:
    I'm looking for a way to establish what IP address a golang http client
    tried to establish an http connection to when making a request, in order to
    add extra information to logs (particularly for debugging CDNs with global
    edge servers and geoDNS etc). Obviously this information is needed for both
    the errors and completed responses.

    Is this information already there, or is there an elegant route to adding
    it?
    Not sure it's available anywhere, but if you make a RoundTripper you can
    write Dial and DialTLS.

    Inside your Dial, call the normal net.Dial. Before returning net.Conn, save
    net.Conn.RemoteAddr().

    --
    Giulio Iotti

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Giulio Iotti at Sep 9, 2015 at 7:59 pm

    On Wednesday, September 9, 2015 at 10:49:10 PM UTC+3, Giulio Iotti wrote:
    Not sure it's available anywhere, but if you make a RoundTripper you can
    write Dial and DialTLS.
    Not RoundTripper but http.Transport, sorry!

    --
    Giulio Iotti

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Daniel Speed at Sep 9, 2015 at 8:07 pm
    I was looking at this, but there's a few things that give me pause:

    The connection can be cached, which means that you probably don't Dial for
    each request.

    There aren't particularly great ways of passing the information back
    (wrapping errors could cause type assertions to fail), and there's no
    particularly great places in http.Response to put the information.

    I'll look further though, thanks.
    On Wednesday, 9 September 2015 19:59:43 UTC, Giulio Iotti wrote:
    On Wednesday, September 9, 2015 at 10:49:10 PM UTC+3, Giulio Iotti wrote:

    Not sure it's available anywhere, but if you make a RoundTripper you can
    write Dial and DialTLS.
    Not RoundTripper but http.Transport, sorry!

    --
    Giulio Iotti
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Giulio Iotti at Sep 9, 2015 at 8:37 pm

    On Wednesday, September 9, 2015 at 11:07:29 PM UTC+3, Daniel Speed wrote:
    I was looking at this, but there's a few things that give me pause:

    The connection can be cached, which means that you probably don't Dial for
    each request.
    That's right, you might need to disable keep alives. :/

    There aren't particularly great ways of passing the information back
    (wrapping errors could cause type assertions to fail), and there's no
    particularly great places in http.Response to put the information.

    I'll look further though, thanks.
    Here is what I could come up with: https://play.golang.org/p/w4gFkO-pwX

    Not sure if it's really correct and I didn't check it with the race
    detector.

    --
    Giulio Iotti

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Brad Fitzpatrick at Sep 10, 2015 at 11:19 pm
    I've referenced this thread from https://github.com/golang/go/issues/12580
    where I'm gathering notes on some similar requests which I suspect will
    share a general solution.

    On Wed, Sep 9, 2015 at 12:21 PM, Daniel Speed wrote:

    I'm looking for a way to establish what IP address a golang http client
    tried to establish an http connection to when making a request, in order to
    add extra information to logs (particularly for debugging CDNs with global
    edge servers and geoDNS etc). Obviously this information is needed for both
    the errors and completed responses.

    Is this information already there, or is there an elegant route to adding
    it?

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 9, '15 at 7:21p
activeSep 10, '15 at 11:19p
posts6
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase