Custom Go services
Dynatrace OneAgent not only detects Go-based web applications and provides full code-level visibility; it also offers support for proprietary application-specific services. Thanks to custom services, you can monitor any Go application service even if Dynatrace doesn't provide built-in support for it. A custom service can be used to quickly monitor functions in any Go application.
Custom services serve multiple purposes:
Service-level visibility for application-specific components.
Response time baselining. This enables the Dynatrace AI to automatically detect changes in response time and identify their root cause.
Failure detection and baselining. The AI not only detects when a custom service failed due to an error; it can also identify the root cause and determine if the failure impacts end-user experience.
Deeper visibility into your application. This gives you request-level end-to-end traces and method hotspots.
Defining a custom service via UI requires the Go application to be instrumented with OneAgent, and the application must be active during service definition.
To define a custom service for short-lived processes, use the Configuration API approach.
Define a custom Go service via UI
To create a new custom Go service
-
From the Dynatrace menu, go to Settings > Service detection > Custom service detection.
-
Select the Go services tab and then select Define Go service.
-
Type a custom name for the service, and then select Find entry point.
-
Find and select the process group that contains your entry point.
-
Select the process that contains your entry point and then select Continue.
-
Find and select the package you want to instrument and then select Continue.
In this example, the scope is
main.(*CronJob)
because the function is defined as a method of theCronJob
type in themain
package. -
Select the required class and then select Continue.
-
Choose one or more functions as entry points for the custom service, and select Finish.
The Define custom service page displays the newly added entry point and methods.
-
{tag kind='optional'}}If needed, add more entry points.
-
{tag kind='optional'}} If needed, restrict the new custom service to certain process groups.
-
Review the entry point and functions to be instrumented. To enable the new custom Go service, select Save in the lower-right corner of the page.
-
Restart the goCron process to allow Dynatrace OneAgent to instrument all entry points defined in custom Go services.
The newly defined service appears in Smartscape, Service flow, and on its own standalone service overview page:
Define a custom Go service via API
To define a custom Go service via API
Prepare the HTTP request
To prepare the HTTP request
-
Determine the scope (
className
)—the package or type the method is defined in.In the following examples, the scope is
main.(*CronJob)
because the function is defined as a method of theCronJob
type in themain
package. -
Determine the fully qualified method name (
methodName
)—the method name, prefixed with the scope.In the following examples, the fully qualified method name is
main.(*CronJob).Run
.
The example request body below contains all the required parameters. To use it, adjust the values according to your request.
1{2 "name": "Cron Job Service",3 "enabled": true,4 "rules": [5 {6 "enabled": true,7 "className": "main.(*CronJob)",8 "methodRules": [9 {10 "methodName": "main.(*CronJob).Run",11 "returnType": ""12 }13 ]14 }15 ],16 "queueEntryPoint": false17}
Send a POST request to your endpoint
- Use
go
as the technology. Use your access token or personal access token for authentication.
1curl --request POST 'https://{your-environment-id}.live.dynatrace.com/api/config/v1/service/customServices/go' \2 --header 'Authorization: Api-Token dt0s01.ST2EY72KQINMH574WMNVI7YN.G3DFPBEJYMODIDAEX454M7YWBUVEFOWKPRVMWFASS64NFH52PX6BNDVFFM572RZM' \3 --header 'Content-Type: application/json' \4 --data '{5 "name": "Cron Job Service",6 "enabled": true,7 "rules": [8 {9 "enabled": true,10 "className": "main.(*CronJob)",11 "methodRules": [12 {13 "methodName": "main.(*CronJob).Run",14 "returnType": ""15 }16 ]17 }18 ],19 "queueEntryPoint": false20 }'
The id
of the newly created custom service is returned upon success; a descriptive error message is returned in case of failure. With this id
, you can edit the custom service via API.
1{2 "id": "114ff497-be8a-44c7-a990-35bb4267b677",3 "name": "Cron Job Service"4}
Closures in Go
Closures are anonymous functions to which the Go compiler assigns special names.
The generated closure names defined in a scope are numbered in order of their appearance: func1
, func2
, and so on. For instance, the closure in the main
function gets the func1
label:
1package main23func main() {4 go func() {5 // ...6 }()7}