Skip to content

Commit

Permalink
elasticapm: add SpanContext.SetHTTPRequest
Browse files Browse the repository at this point in the history
Add the SetHTTPRequest method to SpanContext,
which records the HTTP request URL in the
span context.
axw committed Aug 8, 2018
1 parent 295892b commit 71800e6
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 3 additions & 4 deletions context.go
Original file line number Diff line number Diff line change
@@ -77,10 +77,9 @@ func (c *Context) SetTag(key, value string) {

// SetHTTPRequest sets details of the HTTP request in the context.
//
// This function may be used for either clients or servers. For
// server-side requests, various proxy forwarding headers are taken
// into account to reconstruct the URL, and determining the client
// address.
// This function relates to server-side requests. Various proxy
// forwarding headers are taken into account to reconstruct the URL,
// and determining the client address.
//
// If the request URL contains user info, it will be removed and
// excluded from the URL's "full" field.
13 changes: 13 additions & 0 deletions spancontext.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package elasticapm

import (
"net/http"

"github.com/elastic/apm-agent-go/model"
)

// SpanContext provides methods for setting span context.
type SpanContext struct {
model model.SpanContext
database model.DatabaseSpanContext
http model.HTTPSpanContext
}

// DatabaseSpanContext holds database span context.
@@ -29,6 +32,7 @@ type DatabaseSpanContext struct {
func (c *SpanContext) build() *model.SpanContext {
switch {
case c.model.Database != nil:
case c.model.HTTP != nil:
default:
return nil
}
@@ -44,3 +48,12 @@ func (c *SpanContext) SetDatabase(db DatabaseSpanContext) {
c.database = model.DatabaseSpanContext(db)
c.model.Database = &c.database
}

// SetHTTPRequest sets the details of the HTTP request in the context.
//
// This function relates to client requests. If the request URL contains
// user info, it will be removed and excluded from the stored URL.
func (c *SpanContext) SetHTTPRequest(req *http.Request) {
c.http.URL = req.URL
c.model.HTTP = &c.http
}

0 comments on commit 71800e6

Please sign in to comment.