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

  1. Go to Settings > Service detection > Custom service detection.

  2. Select the Go services tab and then select Define Go service.

    Go services tab

  3. Type a custom name for the service, and then select Find entry point.

  4. Find and select the process group that contains your entry point.

  5. Select the process that contains your entry point and then select Continue.

  6. Find and select the package you want to instrument and then select Continue.

    Choose a package or type

    In this example, the scope is main.(*CronJob) because the function is defined as a method of the CronJob type in the main package.

  7. Select the required class and then select Continue.

  8. 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.

    Choose a function

  9. optionalIf needed, add more entry points.

  10. optional If needed, restrict the new custom service to certain process groups.

  11. 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.

    Enable Go service

  12. 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:

Service overview page - cron job service

Service flow - cron job service.png

PurePath - cron job service

Define a custom Go service via API

To define a custom Go service via API

Step 1 Prepare the HTTP request

To prepare the HTTP request

  1. 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.

  2. 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
}

Step 2 Send a POST request to your endpoint

  • Use go as the technology.
  • Use your access token or personal access token for authentication.
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 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:

package main
func main() {
go func() {
// ...
}()
}