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:
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.
To create a new custom Go service
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 the CronJob
type in the main
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.
optionalIf needed, add more entry points.
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:
To define a custom Go service via API
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 the CronJob
type in the main
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.
{"name": "Cron Job Service","enabled": true,"rules": [{"enabled": true,"className": "main.(*CronJob)","methodRules": [{"methodName": "main.(*CronJob).Run","returnType": ""}]}],"queueEntryPoint": false}
go
as the technology.curl --request POST 'https://{your-environment-id}.live.dynatrace.com/api/config/v1/service/customServices/go' \--header 'Authorization: Api-Token dt0s01.ST2EY72KQINMH574WMNVI7YN.G3DFPBEJYMODIDAEX454M7YWBUVEFOWKPRVMWFASS64NFH52PX6BNDVFFM572RZM' \--header 'Content-Type: application/json' \--data '{"name": "Cron Job Service","enabled": true,"rules": [{"enabled": true,"className": "main.(*CronJob)","methodRules": [{"methodName": "main.(*CronJob).Run","returnType": ""}]}],"queueEntryPoint": false}'
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.
{"id": "114ff497-be8a-44c7-a990-35bb4267b677","name": "Cron Job Service"}
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:
package mainfunc main() {go func() {// ...}()}