Browse documentation
Get started
SDKs
Metrics
Monitor
Workspace and access
Go SDK
Install the Go metrics SDK, authenticate with an M2M credential, and call the Metrics API with a context-aware client.
The official Go SDK provides typed operation requests and responses, local request validation, automatic M2M token exchange, and typed API errors.
Use the API reference when you need the parameters and response schema for a specific operation.
Requirements
The SDK requires Go 1.24 or newer. Add the module to your project:
go get github.com/omascloud/sdks/go/metricsImport core for the shared authentication runtime and metrics for the generated Metrics client and models.
Configure authentication
Use an exchange-only M2M credential for a service, job, or other unattended workload. On the API tokens page, create a token and select Exchange only as its access mode. Store the credential in your secret manager and expose it to the process as OMAS_M2M_TOKEN; never commit it to source control.
The authentication provider exchanges the credential for short-lived, metrics-scoped access tokens and refreshes them automatically. A token created in Direct mode is not the credential this provider expects.
Create a client
Create the provider and client once, reuse them across requests, and close both when the application shuts down:
package main
import (
"context"
"fmt"
"os"
"github.com/omascloud/sdks/go/core"
"github.com/omascloud/sdks/go/metrics"
)
func main() {
authProvider, err := core.NewM2MAuthProvider(os.Getenv("OMAS_M2M_TOKEN"))
if err != nil {
panic(err)
}
defer authProvider.Close()
client, err := metrics.NewClient(authProvider)
if err != nil {
panic(err)
}
defer client.Close()
maxResults := int32(25)
response, err := client.ListMetrics(
context.Background(),
metrics.ListMetricsOperationRequest{MaxResults: &maxResults},
)
if err != nil {
panic(err)
}
for _, metric := range response.Metrics {
fmt.Println(metric.Name)
}
}Pass a request-scoped context so callers can propagate cancellation and deadlines.
Handle errors
Every documented service error has a generated Go type that you can inspect with errors.As. Each typed error embeds *core.APIError, which retains the HTTP status, error code, message, response headers, request ID, retry delay, and raw response body:
var notFound *metrics.ResourceNotFoundError
if errors.As(err, ¬Found) {
fmt.Printf(
"request %s failed with status %d\n",
notFound.RequestID,
notFound.StatusCode,
)
if notFound.Details != nil && notFound.Details.Field != nil {
fmt.Printf("missing field: %s\n", *notFound.Details.Field)
}
}Unknown server error codes remain available as *core.APIError, so the client remains forward-compatible. Log the request ID when it is available and retry only when the failure and operation make that safe.
Next steps
- Browse the API reference for operation parameters, responses, and documented errors.
- Review the public SDK repository for source code and release information.
- Read Metric rollups and resolution before choosing production query settings.