Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add app.environment #366

Merged
merged 3 commits into from Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Expand Up @@ -15,6 +15,7 @@ https://github.com/elastic/apm-server/compare/71df0d96445df35afe27f38bcf734a0828

==== Added
- Support for uploading sourcemaps {pull}302[302].
- app.environment {pull}366[366]

==== Deprecated

Expand Down
5 changes: 5 additions & 0 deletions _meta/fields.common.yml
Expand Up @@ -168,6 +168,11 @@
description: >
App process_title.

- name: environment
type: keyword
description: >
App environment.

- name: language
type: group
fields:
Expand Down
1 change: 1 addition & 0 deletions docs/data/elasticsearch/error.json
Expand Up @@ -9,6 +9,7 @@
"node",
"server.js"
],
"environment": "staging",
"framework": {
"name": "Express",
"version": "1.2.3"
Expand Down
1 change: 1 addition & 0 deletions docs/data/elasticsearch/transaction.json
Expand Up @@ -9,6 +9,7 @@
"node",
"server.js"
],
"environment": "staging",
"framework": {
"name": "Express",
"version": "1.2.3"
Expand Down
19 changes: 10 additions & 9 deletions docs/data/intake-api/generated/error/null_values.json
Expand Up @@ -4,16 +4,17 @@
"language": {
"name": "ruby",
"version": null
},
},
"agent": {
"name": "ruby",
"version": "1.0.0"
},
"version": null,
"pid": null,
"process_title": null,
"environment": null,
"argv": null,
"runtime": null,
"runtime": null,
"framework": null
},
"system": {
Expand Down Expand Up @@ -53,16 +54,16 @@
"context": {
"request": {
"socket": {
"remote_address": null,
"encrypted": null
"remote_address": null,
"encrypted": null
},
"method": "POST",
"headers": {
"user-agent": null,
"content-type": null,
"content-type": null,
"cookie": null
},
"url": {}
"url": {}
},
"response": {
"headers": {
Expand Down Expand Up @@ -96,7 +97,7 @@
"method": "POST",
"http_version": null,
"url": {
"protocol": null,
"protocol": null,
"hostname": null,
"port": null,
"pathname": null,
Expand All @@ -113,10 +114,10 @@
"status_code": null,
"headers": null,
"headers_sent": null,
"finished": null
"finished": null
},
"user": {
"id": null,
"id": null,
"username": null,
"email": null
},
Expand Down
1 change: 1 addition & 0 deletions docs/data/intake-api/generated/error/payload.json
Expand Up @@ -4,6 +4,7 @@
"version": "5.1.3",
"pid": 1234,
"process_title": "node",
"environment": "staging",
"argv": [
"node",
"server.js"
Expand Down
21 changes: 11 additions & 10 deletions docs/data/intake-api/generated/transaction/null_values.json
Expand Up @@ -4,16 +4,17 @@
"language": {
"name": "ruby",
"version": null
},
},
"agent": {
"name": "ruby",
"version": "1.0.0"
},
"version": null,
"pid": null,
"process_title": null,
"environment": null,
"argv": null,
"runtime": null,
"runtime": null,
"framework": null
},
"system": {
Expand Down Expand Up @@ -58,7 +59,7 @@
"method": "POST",
"http_version": null,
"url": {
"protocol": null,
"protocol": null,
"hostname": null,
"port": null,
"pathname": null,
Expand All @@ -75,10 +76,10 @@
"status_code": null,
"headers": null,
"headers_sent": null,
"finished": null
"finished": null
},
"user": {
"id": null,
"id": null,
"username": null,
"email": null
},
Expand All @@ -94,16 +95,16 @@
"context": {
"request": {
"socket": {
"remote_address": null,
"encrypted": null
"remote_address": null,
"encrypted": null
},
"method": "POST",
"headers": {
"user-agent": null,
"content-type": null,
"content-type": null,
"cookie": null
},
"url": {}
"url": {}
},
"response": {
"headers": {
Expand Down Expand Up @@ -155,7 +156,7 @@
"post_context": null,
"pre_context": null,
"vars": null
}]
}]
},
{
"name": "GET /api/types",
Expand Down
1 change: 1 addition & 0 deletions docs/data/intake-api/generated/transaction/payload.json
Expand Up @@ -4,6 +4,7 @@
"version": "5.1.3",
"pid": 1234,
"process_title": "node",
"environment": "staging",
"argv": [
"node",
"server.js"
Expand Down
8 changes: 8 additions & 0 deletions docs/fields.asciidoc
Expand Up @@ -257,6 +257,14 @@ type: keyword
App process_title.


[float]
=== `context.app.environment`

type: keyword

App environment.



[float]
=== `context.app.language.name`
Expand Down
4 changes: 4 additions & 0 deletions docs/spec/app.json
Expand Up @@ -63,6 +63,10 @@
"type": ["string", "null"],
"maxLength": 1024
},
"environment": {
"type": ["string", "null"],
"maxLength": 1024
},
"runtime": {
"type": ["object", "null"],
"properties": {
Expand Down
2 changes: 2 additions & 0 deletions model/app.go
Expand Up @@ -10,6 +10,7 @@ type App struct {
Version *string `json:"version"`
Pid *int `json:"pid"`
ProcessTitle *string `json:"process_title"`
Environment *string `json:"environment"`
Argv []string `json:"argv"`
Language Language `json:"language"`
Runtime Runtime `json:"runtime"`
Expand Down Expand Up @@ -53,6 +54,7 @@ func (a *App) Transform() common.MapStr {
enhancer.Add(app, "version", a.Version)
enhancer.Add(app, "pid", a.Pid)
enhancer.Add(app, "process_title", a.ProcessTitle)
enhancer.Add(app, "environment", a.Environment)
enhancer.Add(app, "argv", a.Argv)

lang := common.MapStr{}
Expand Down
3 changes: 3 additions & 0 deletions model/app_test.go
Expand Up @@ -19,6 +19,7 @@ func TestAppTransform(t *testing.T) {
version := "5.1.3"
pid := 1234
processTitle := "node"
environment := "staging"
langName := "ecmascript"
langVersion := "8"
rtName := "node"
Expand Down Expand Up @@ -47,6 +48,7 @@ func TestAppTransform(t *testing.T) {
Version: &version,
Pid: &pid,
ProcessTitle: &processTitle,
Environment: &environment,
Argv: []string{
"node",
"server.js",
Expand All @@ -71,6 +73,7 @@ func TestAppTransform(t *testing.T) {
Output: common.MapStr{
"name": "myapp",
"version": "5.1.3",
"environment": "staging",
"pid": 1234,
"process_title": "node",
"argv": []string{
Expand Down
Expand Up @@ -12,6 +12,7 @@
"node",
"server.js"
],
"environment": "staging",
"framework": {
"name": "Express",
"version": "1.2.3"
Expand Down Expand Up @@ -256,6 +257,7 @@
"node",
"server.js"
],
"environment": "staging",
"framework": {
"name": "Express",
"version": "1.2.3"
Expand Down Expand Up @@ -304,6 +306,7 @@
"node",
"server.js"
],
"environment": "staging",
"framework": {
"name": "Express",
"version": "1.2.3"
Expand Down Expand Up @@ -351,6 +354,7 @@
"node",
"server.js"
],
"environment": "staging",
"framework": {
"name": "Express",
"version": "1.2.3"
Expand Down
4 changes: 4 additions & 0 deletions processor/error/schema.go
Expand Up @@ -76,6 +76,10 @@ var errorSchema = `{
"type": ["string", "null"],
"maxLength": 1024
},
"environment": {
"type": ["string", "null"],
"maxLength": 1024
},
"runtime": {
"type": ["object", "null"],
"properties": {
Expand Down
Expand Up @@ -12,6 +12,7 @@
"node",
"server.js"
],
"environment": "staging",
"framework": {
"name": "Express",
"version": "1.2.3"
Expand Down Expand Up @@ -287,6 +288,7 @@
"node",
"server.js"
],
"environment": "staging",
"framework": {
"name": "Express",
"version": "1.2.3"
Expand Down Expand Up @@ -336,6 +338,7 @@
"node",
"server.js"
],
"environment": "staging",
"framework": {
"name": "Express",
"version": "1.2.3"
Expand Down Expand Up @@ -385,6 +388,7 @@
"node",
"server.js"
],
"environment": "staging",
"framework": {
"name": "Express",
"version": "1.2.3"
Expand Down
4 changes: 4 additions & 0 deletions processor/transaction/schema.go
Expand Up @@ -76,6 +76,10 @@ var transactionSchema = `{
"type": ["string", "null"],
"maxLength": 1024
},
"environment": {
"type": ["string", "null"],
"maxLength": 1024
},
"runtime": {
"type": ["object", "null"],
"properties": {
Expand Down
16 changes: 7 additions & 9 deletions script/inline_schemas/inline_schemas.go
Expand Up @@ -11,17 +11,15 @@ import (
const basePath = "./docs/spec/"

func main() {
schemaPaths := [][]string{
schemaPaths := []struct {
path, schemaOut, goVariable, packageName string
}{
{"errors/payload.json", "processor/error/schema.go", "errorSchema", "error"},
{"transactions/payload.json", "processor/transaction/schema.go", "transactionSchema", "transaction"},
{"sourcemaps/payload.json", "processor/sourcemap/schema.go", "sourcemapSchema", "sourcemap"},
}
for _, schemaInfo := range schemaPaths {
file := filepath.Join(filepath.Dir(basePath), schemaInfo[0])
schemaOut := schemaInfo[1]
goVariable := schemaInfo[2]
packageName := schemaInfo[3]

file := filepath.Join(filepath.Dir(basePath), schemaInfo.path)
schemaBytes, err := ioutil.ReadFile(file)
if err != nil {
panic(err)
Expand All @@ -32,9 +30,9 @@ func main() {
panic(err)
}

publicSchema := fmt.Sprintf("func Schema() string {\n\treturn %s\n}\n", goVariable)
goScript := fmt.Sprintf("package %s\n\n%s\nvar %s = `%s`\n", packageName, publicSchema, goVariable, schema)
err = ioutil.WriteFile(schemaOut, []byte(goScript), 0644)
publicSchema := fmt.Sprintf("func Schema() string {\n\treturn %s\n}\n", schemaInfo.goVariable)
goScript := fmt.Sprintf("package %s\n\n%s\nvar %s = `%s`\n", schemaInfo.packageName, publicSchema, schemaInfo.goVariable, schema)
err = ioutil.WriteFile(schemaInfo.schemaOut, []byte(goScript), 0644)
if err != nil {
panic(err)
}
Expand Down