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

Outcome #820

Merged
merged 5 commits into from
Sep 24, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ https://github.com/elastic/apm-agent-go/compare/v1.8.0...master[View commits]
- Deprecate IGNORE_URLS, replace with TRANSACTION_IGNORE_URLS {pull}811[(#811)]
- Tracer.Close now waits for the transport goroutine to end before returning {pull}816[#(816)]
- Relax Kubernetes pod UID discovery rules {pull}819[#(819)]
- Add transaction and span outcome {pull}820[#(820)]

[[release-notes-1.x]]
=== Go Agent version 1.x
Expand Down
16 changes: 16 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ func (c *Context) SetHTTPResponseHeaders(h http.Header) {
}

// SetHTTPStatusCode records the HTTP response status code.
//
// If, when the transaction ends, its Outcome field has not
// been explicitly set, it will be set based on the status code:
// "success" if statusCode < 500, and "failure" otherwise.
func (c *Context) SetHTTPStatusCode(statusCode int) {
c.response.StatusCode = statusCode
c.model.Response = &c.response
Expand Down Expand Up @@ -254,3 +258,15 @@ func (c *Context) SetUsername(username string) {
c.model.User = &c.user
}
}

// outcome returns the outcome to assign to the associated transaction,
// based on context (e.g. HTTP status code).
func (c *Context) outcome() string {
if c.response.StatusCode != 0 {
if c.response.StatusCode < 500 {
return "success"
}
return "failure"
}
return ""
}
108 changes: 108 additions & 0 deletions internal/apmschema/jsonschema/cloud.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"$id": "docs/spec/cloud.json",
"title": "Cloud",
"type": [
"object",
"null"
],
"properties": {
"account": {
"properties": {
"id": {
"description": "Cloud account ID",
"type": [
"string",
"null"
],
"maxLength": 1024
},
"name": {
"description": "Cloud account name",
"type": [
"string",
"null"
],
"maxLength": 1024
}
}
},
"availability_zone": {
"description": "Cloud availability zone name. e.g. us-east-1a",
"type": [
"string",
"null"
],
"maxLength": 1024
},
"instance": {
"properties": {
"id": {
"description": "Cloud instance/machine ID",
"type": [
"string",
"null"
],
"maxLength": 1024
},
"name": {
"description": "Cloud instance/machine name",
"type": [
"string",
"null"
],
"maxLength": 1024
}
}
},
"machine": {
"properties": {
"type": {
"description": "Cloud instance/machine type",
"type": [
"string",
"null"
],
"maxLength": 1024
}
}
},
"project": {
"properties": {
"id": {
"description": "Cloud project ID",
"type": [
"string",
"null"
],
"maxLength": 1024
},
"name": {
"description": "Cloud project name",
"type": [
"string",
"null"
],
"maxLength": 1024
}
}
},
"provider": {
"description": "Cloud provider name. e.g. aws, azure, gcp, digitalocean.",
"type": [
"string"
],
"maxLength": 1024
},
"region": {
"description": "Cloud region name. e.g. us-east-1",
"type": [
"string",
"null"
],
"maxLength": 1024
}
},
"required": [
"provider"
]
}
41 changes: 18 additions & 23 deletions internal/apmschema/jsonschema/context.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$id": "doc/spec/context.json",
"$id": "docs/spec/context.json",
"title": "Context",
"description": "Any arbitrary contextual information regarding the event, captured by the agent, optionally provided by the user",
"type": ["object", "null"],
Expand All @@ -14,31 +14,26 @@
},
"response": {
"type": ["object", "null"],
"properties": {
"finished": {
"description": "A boolean indicating whether the response was finished or not",
"type": ["boolean", "null"]
},
"headers": {
"description": "A mapping of HTTP headers of the response object",
"type": ["object", "null"],
"patternProperties": {
"[.*]*$": {
"type": ["string", "array", "null"],
"items": {
"type": ["string"]
}
"allOf": [
{ "$ref": "./http_response.json" },
{
"properties": {
"finished": {
"description": "A boolean indicating whether the response was finished or not",
"type": [
"boolean",
"null"
]
},
"headers_sent": {
"type": [
"boolean",
"null"
]
}
}
},
"headers_sent": {
"type": ["boolean", "null"]
},
"status_code": {
"description": "The HTTP status code of the response.",
"type": ["integer", "null"]
}
}
]
},
"request": {
"$ref": "request.json"
Expand Down
35 changes: 35 additions & 0 deletions internal/apmschema/jsonschema/http_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$id": "docs/spec/http_response.json",
"title": "HTTP response object",
"description": "HTTP response object, used by error, span and transction documents",
"type": ["object", "null"],
"properties": {
"status_code": {
"type": ["integer", "null"],
"description": "The status code of the http request."
},
"transfer_size": {
"type": ["number", "null"],
"description": "Total size of the payload."
},
"encoded_body_size": {
"type": ["number", "null"],
"description": "The encoded size of the payload."
},
"decoded_body_size": {
"type": ["number", "null"],
"description": "The decoded size of the payload."
},
"headers": {
"type": ["object", "null"],
"patternProperties": {
"[.*]*$": {
"type": ["string", "array", "null"],
"items": {
"type": ["string"]
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion internal/apmschema/jsonschema/message.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$id": "doc/spec/message.json",
"$id": "docs/spec/message.json",
"title": "Message",
"description": "Details related to message receiving and publishing if the captured event integrates with a messaging system",
"type": ["object", "null"],
Expand Down
Loading