Skip to content

Commit

Permalink
use updated default service name (#1231)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartnelson3 authored Mar 23, 2022
1 parent 27eb50e commit 0a6f11e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ https://github.com/elastic/apm-agent-go/compare/v2.0.0...main[View commits]
- Removed SetTag {pull}1218[(#1218)]
- Unexport Tracer's fields -- TracerOptions must be used instead {pull}1219[#(1219)]
- Replace `authorization` with `*auth*` pattern for sanitizing field names {pull}1230[#(1230)]
- Default service name is now `unknown-go-service` {pull}1231[#(1231)]
[[release-notes-1.x]]
=== Go Agent version 1.x
Expand Down
7 changes: 1 addition & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import (
"fmt"
"net/url"
"os"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"sync/atomic"
Expand Down Expand Up @@ -283,10 +281,7 @@ func initialService() (name, version, environment string) {
version = os.Getenv(envServiceVersion)
environment = os.Getenv(envEnvironment)
if name == "" {
name = filepath.Base(os.Args[0])
if runtime.GOOS == "windows" {
name = strings.TrimSuffix(name, filepath.Ext(name))
}
name = "unknown-go-service"
}
name = sanitizeServiceName(name)
return name, version, environment
Expand Down
7 changes: 3 additions & 4 deletions docs/configuration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,15 @@ your communications using HTTPS. Unless you do so, your API Key could be observe
[options="header"]
|============
| Environment | Default | Example
| `ELASTIC_APM_SERVICE_NAME` | Executable name | `my-app`
| `ELASTIC_APM_SERVICE_NAME` | unknown-go-service | `my-app`
|============

The name of your service or application. This is used to keep all the errors and
transactions of your service together and is the primary filter in the Elastic APM
user interface.

If you do not specify `ELASTIC_APM_SERVICE_NAME`, the Go agent will use the
executable name. e.g. if your executable is called "my-app.exe", then your
service will be identified as "my-app".
If you do not specify `ELASTIC_APM_SERVICE_NAME`, the Go agent will use
`unknown-go-service`.

NOTE: The service name must conform to this regular expression: `^[a-zA-Z0-9 _-]+$`.
In other words: your service name must only contain characters from the ASCII
Expand Down
4 changes: 2 additions & 2 deletions env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ func TestTracerServiceNameEnvSanitizationSpecified(t *testing.T) {
assert.Equal(t, "foo_bar", service.Name)
}

func TestTracerServiceNameEnvSanitizationExecutableName(t *testing.T) {
func TestTracerServiceNameDefault(t *testing.T) {
_, _, service, _ := getSubprocessMetadata(t)
assert.Equal(t, "apm_test", service.Name) // .test -> _test
assert.Equal(t, "unknown-go-service", service.Name)
}

func TestTracerGlobalLabelsUnspecified(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type TracerOptions struct {
//
// If ServiceName is empty, the service name will be defined using the
// ELASTIC_APM_SERVICE_NAME environment variable, or if that is not set,
// the executable name.
// unknown-go-service will be used.
ServiceName string

// ServiceVersion holds the service version.
Expand Down

0 comments on commit 0a6f11e

Please sign in to comment.