-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Elastic | ||
|
||
To enable the Elastic: | ||
|
||
```toml tab="File (TOML)" | ||
[tracing] | ||
[tracing.elastic] | ||
``` | ||
|
||
```yaml tab="File (YAML)" | ||
tracing: | ||
elastic: {} | ||
``` | ||
|
||
```bash tab="CLI" | ||
--tracing.elastic=true | ||
``` | ||
|
||
#### `serverURL` | ||
|
||
_Optional, Default="http://localhost:8200"_ | ||
|
||
APM ServerURL is the URL of the Elastic APM server. | ||
|
||
```toml tab="File (TOML)" | ||
[tracing] | ||
[tracing.elastic] | ||
serverURL = "http://apm:8200" | ||
``` | ||
|
||
```yaml tab="File (YAML)" | ||
tracing: | ||
elastic: | ||
serverURL: "http://apm:8200" | ||
``` | ||
|
||
```bash tab="CLI" | ||
--tracing.elastic.serverurl="http://apm:8200" | ||
``` | ||
|
||
#### `secretToken` | ||
|
||
_Optional, Default=""_ | ||
|
||
APM Secret Token is the token used to connect to Elastic APM Server. | ||
|
||
```toml tab="File (TOML)" | ||
[tracing] | ||
[tracing.elastic] | ||
secretToken = "mytoken" | ||
``` | ||
|
||
```yaml tab="File (YAML)" | ||
tracing: | ||
elastic: | ||
secretToken: "mytoken" | ||
``` | ||
|
||
```bash tab="CLI" | ||
--tracing.elastic.secrettoken="mytoken" | ||
``` | ||
|
||
#### `serviceEnvironment` | ||
|
||
_Optional, Default=""_ | ||
|
||
APM Service Environment is the name of the environment Traefik is deployed in, e.g. `production` or `staging`. | ||
|
||
```toml tab="File (TOML)" | ||
[tracing] | ||
[tracing.elastic] | ||
serviceEnvironment = "production" | ||
``` | ||
|
||
```yaml tab="File (YAML)" | ||
tracing: | ||
elastic: | ||
serviceEnvironment: "production" | ||
``` | ||
|
||
```bash tab="CLI" | ||
--tracing.elastic.serviceenvironment="production" | ||
``` | ||
|
||
### Further | ||
|
||
Additional configuration of Elastic APM Go agent can be done using environment variables. | ||
See [APM Go agent reference](https://www.elastic.co/guide/en/apm/agent/go/current/configuration.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package elastic | ||
|
||
import ( | ||
"io" | ||
"net/url" | ||
|
||
"github.com/containous/traefik/v2/pkg/log" | ||
"github.com/containous/traefik/v2/pkg/version" | ||
"github.com/opentracing/opentracing-go" | ||
"go.elastic.co/apm" | ||
"go.elastic.co/apm/module/apmot" | ||
"go.elastic.co/apm/transport" | ||
) | ||
|
||
// Name sets the name of this tracer. | ||
const Name = "elastic" | ||
|
||
// Config provides configuration settings for a elastic.co tracer. | ||
type Config struct { | ||
ServerURL string `description:"Set the URL of the Elastic APM server." json:"serverURL,omitempty" toml:"serverURL,omitempty" yaml:"serverURL,omitempty"` | ||
SecretToken string `description:"Set the token used to connect to Elastic APM Server." json:"secretToken,omitempty" toml:"secretToken,omitempty" yaml:"secretToken,omitempty"` | ||
ServiceEnvironment string `description:"Set the name of the environment Traefik is deployed in, e.g. 'production' or 'staging'." json:"serviceEnvironment,omitempty" toml:"serviceEnvironment,omitempty" yaml:"serviceEnvironment,omitempty"` | ||
} | ||
|
||
// Setup sets up the tracer. | ||
func (c *Config) Setup(serviceName string) (opentracing.Tracer, io.Closer, error) { | ||
// Create default transport. | ||
tr, err := transport.NewHTTPTransport() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
if c.ServerURL != "" { | ||
serverURL, err := url.Parse(c.ServerURL) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
tr.SetServerURL(serverURL) | ||
} | ||
|
||
if c.SecretToken != "" { | ||
tr.SetSecretToken(c.SecretToken) | ||
} | ||
|
||
tracer, err := apm.NewTracerOptions(apm.TracerOptions{ | ||
ServiceName: serviceName, | ||
ServiceVersion: version.Version, | ||
ServiceEnvironment: c.ServiceEnvironment, | ||
Transport: tr, | ||
}) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
tracer.SetLogger(log.WithoutContext()) | ||
otTracer := apmot.New(apmot.WithTracer(tracer)) | ||
|
||
// Without this, child spans are getting the NOOP tracer | ||
opentracing.SetGlobalTracer(otTracer) | ||
|
||
log.WithoutContext().Debug("Elastic tracer configured") | ||
|
||
return otTracer, nil, nil | ||
} |