Skip to content

Commit

Permalink
Deprecate IGNORE_URLS and replace with TRANSACTION_IGNORE_URLS (#811)
Browse files Browse the repository at this point in the history
Closes #792
  • Loading branch information
jalvz committed Sep 1, 2020
1 parent ee97405 commit 65fb3f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
9 changes: 6 additions & 3 deletions docs/configuration.asciidoc
Expand Up @@ -258,12 +258,12 @@ server versions.

[float]
[[config-ignore-urls]]
=== `ELASTIC_APM_IGNORE_URLS`
=== `ELASTIC_APM_TRANSACTION_IGNORE_URLS`

[options="header"]
|============
| Environment | Default | Example
| `ELASTIC_APM_IGNORE_URLS` | | `/heartbeat*, *.jpg`
| Environment | Default | Example
| `ELASTIC_APM_TRANSACTION_IGNORE_URLS` | | `/heartbeat*, *.jpg`
|============

A list of patterns to match HTTP requests to ignore. An incoming HTTP request
Expand All @@ -273,6 +273,9 @@ This option supports the wildcard `*`, which matches zero or more characters.
Examples: `/foo/*/bar/*/baz*`, `*foo*`. Matching is case insensitive by default.
Prefixing a pattern with `(?-i)` makes the matching case sensitive.

NOTE: this configuration was previously known as `ELASTIC_APM_IGNORE_URLS`, which has been deprecated and will be removed in a future major
version of the agent.

[float]
[[config-sanitize-field-names]]
=== `ELASTIC_APM_SANITIZE_FIELD_NAMES`
Expand Down
8 changes: 6 additions & 2 deletions module/apmhttp/ignorer.go
Expand Up @@ -27,7 +27,8 @@ import (
)

const (
envIgnoreURLs = "ELASTIC_APM_IGNORE_URLS"
envIgnoreURLs = "ELASTIC_APM_TRANSACTION_IGNORE_URLS"
deprecatedEnvIgnoreURLs = "ELASTIC_APM_IGNORE_URLS"
)

var (
Expand All @@ -36,12 +37,15 @@ var (
)

// DefaultServerRequestIgnorer returns the default RequestIgnorer to use in
// handlers. If ELASTIC_APM_IGNORE_URLS is set, it will be treated as a
// handlers. If ELASTIC_APM_TRANSACTION_IGNORE_URLS is set, it will be treated as a
// comma-separated list of wildcard patterns; requests that match any of the
// patterns will be ignored.
func DefaultServerRequestIgnorer() RequestIgnorerFunc {
defaultServerRequestIgnorerOnce.Do(func() {
matchers := configutil.ParseWildcardPatternsEnv(envIgnoreURLs, nil)
if len(matchers) == 0 {
matchers = configutil.ParseWildcardPatternsEnv(deprecatedEnvIgnoreURLs, nil)
}
if len(matchers) != 0 {
defaultServerRequestIgnorer = NewWildcardPatternsRequestIgnorer(matchers)
}
Expand Down
15 changes: 14 additions & 1 deletion module/apmhttp/ignorer_test.go
Expand Up @@ -61,11 +61,24 @@ func testDefaultServerRequestIgnorer(t *testing.T, ignoreURLs string, r *http.Re
if os.Getenv("_INSIDE_TEST") != "1" {
cmd := exec.Command(os.Args[0], "-test.run=^"+regexp.QuoteMeta(t.Name())+"$")
cmd.Env = append(os.Environ(), "_INSIDE_TEST=1")
cmd.Env = append(cmd.Env, "ELASTIC_APM_IGNORE_URLS="+ignoreURLs)
cmd.Env = append(cmd.Env, "ELASTIC_APM_TRANSACTION_IGNORE_URLS="+ignoreURLs)
assert.NoError(t, cmd.Run())
return
}
ignorer := apmhttp.DefaultServerRequestIgnorer()
assert.Equal(t, expect, ignorer(r))
})
}

func TestFallbackDeprecatedRequestIgnorer(t *testing.T) {
if os.Getenv("_INSIDE_TEST") != "1" {
cmd := exec.Command(os.Args[0], "-test.run=^"+regexp.QuoteMeta(t.Name())+"$")
cmd.Env = append(os.Environ(), "_INSIDE_TEST=1")
cmd.Env = append(cmd.Env, "ELASTIC_APM_IGNORE_URLS=*/foo*")
assert.NoError(t, cmd.Run())
return
}
req := &http.Request{URL: &url.URL{Path: "/foo"}}
ignorer := apmhttp.DefaultServerRequestIgnorer()
assert.Equal(t, true, ignorer(req))
}

0 comments on commit 65fb3f0

Please sign in to comment.