Use the Go SDK to instrument Google Go applications. The API includes functions for creating business transactions, transaction backends, exit points, and so on. See Use Go SDK.

Basic Types

The Go SDK defines these opaque types:

Config Struct

The Config struct contains settings used by the agent to connect to the Controller. The structure serves an equivalent function of the agent configuration files described in Agent-to-Controller Connections

The Config struct is defined as follows:

type Config struct {
    AppName, TierName, NodeName string
    Controller Controller
    InitTimeoutMs int
    Initialized uint // a special field used by the underlying AppDynamics libraries. Do not use.
    Logging LoggingConfig
    UseConfigFromEnv bool
    EnvVarPrefix string
}

The structure is made up of these fields:

If the agent needs to connect to the Controller via a local HTTP proxy server, you need to configure the settings for the proxy server. You can do so using the HTTPProxy struct, defined as follows:

type HTTPProxy struct {
    Host string
    Port uint16
    Username, PasswordFile string
}

The HTTPProxy struct has the following fields: 

ContextConfig Struct

You use the ContextConfig struct for calls that apply to multi-tenant Controller environments. 

type ContextConfig struct {
    AppName string
    TierName string
    NodeName string
}

The ContextConfig struct has these fields:

AddAppContextToConfig

Add application context to the configuration for a multi-tenant Controller.

Format 

func AddAppContextToConfig(cfg *Config, context string, contextCfg *ContextConfig) error 

Parameters

InitSDK

Initialize the Go SDK. An instrumented application must call this function once, preferably during application startup.

Format 
func InitSDK(cfg *Config) error 
Parameter

cfg: configuration settings that enable communication between the agent and the Controller.

Returns

nil on success, otherwise an error value

TerminateSDK

Stop the Go SDK. Ends all active business transactions for this agent and stops agent metric reporting to the Controller.

Format 
func TerminateSDK() 

StartBT

Start a business transaction or continue an existing transaction. 

Keep in mind that each application is limited to 200 registered business transactions, and each agent is limited to 50 registered business transactions. Unlike transactions discovered by other types of agents, business transactions that exceed the limit that are reported by the Go SDK are not included in the all other traffic grouping. This means that it's up to you to ensure that your agent does not create excessive business transactions. Use care to ensure that your implementation does not introduce the possibility of business transaction explosion.

Format 

func StartBT(name, correlation_header string) BtHandle  

Parameters
Returns

An opaque handle for the business transaction that was started.

StartBTWithAppContext

Start a business transaction or continue an existing transaction in a multi-tenant Controller environment. 

Format

func StartBTWithAppContext(context, name, correlation_header string) BtHandle 

Parameters

EndBT

End the given business transaction.

Format

func EndBT(bt BtHandle) 

Parameter

bt: The handle to the business transaction to end.

GetBT

Get a BT handle associated with the given guid by appd_bt_store.

Format 

func GetBT(guid string) BtHandle 

Parameter

guid: The globally unique identifier that was passed to appd_bt_store.

Returns

The handle to the business transaction associated with the given guid.

In the following cases the SDK logs a warning and returns a handle that you may safely use in other API functions but that will cause these functions to immediately return without doing anything:

IsBTSnapshotting

Reports whether the agent is currently taking a transaction snapshot. Useful before calling AddUserDataToBT or SetBTURL, since those potentially expensive functions would do nothing if called when a snapshot is not being taken.

Format

func IsBTSnapshotting(bt BtHandle) bool 

Parameter

bt: The handle to the business transaction to check for snapshotting. 

Returns

true if the given business transaction is taking a snapshot. Otherwise, false. 

SetBTURL

Set the URL for a snapshot, if one is being taken. It is safe to call this function when a snapshot is not occurring. When the given business transaction is not snapshotting, this function immediately returns. However, if extracting the data to pass to this function is expensive, you can use IsBTSnapshotting to check if the business transaction is snapshotting before extracting the data and calling this function. The url argument data should be either 7-bit ASCII or UTF-8.

Format 

func SetBTURL(bt BtHandle, url string)

Parameters

StoreBT

Store a BT handle in a global registry to retrieve later with GetBT. This is convenient when you need to start and end a business transaction in separate places, and it is difficult to pass the handle to the business transaction through the parts of the code that need it.

When the business transaction is ended, the handle is removed from the global registry.

Format

func StoreBT(bt BtHandle, guid string) 

Parameters

AddBTError

Add an error to a business transaction. Errors are reported as part of the business transaction. However, you can add an error without marking the business transaction as an error (e.g., for non-fatal errors).

Format 

func AddBTError(bt BtHandle, level ErrorLevel, message string, mark_bt_as_error bool) 

Parameters

AddUserDataToBT

Attaches user data to transaction snapshots generated for the specified business transaction.

The user data is added to the business transaction but reported only when a transaction snapshot is occurring. In the Controller UI, the user data appears in the USER DATA tab of the transaction snapshot details.

It is safe to call this function when a snapshot is not occurring. When the specified business transaction is not taking a snapshot, this function immediately returns.

If extracting the data to pass to this function is expensive, you can use IsBTSnapshotting to check if the business transaction is actually taking a snapshot before extracting the data and calling this function.

The data in the value argument should be either 7-bit ASCII or UTF-8.

Format

func AddUserDataToBT(bt BtHandle, key, value string) 

Parameters

AddBackend

Add a backend to the business application

This function fails if the type of the backend being added does not have at least one identifying property.

Format

func AddBackend(name, backendType string, identifyingProperties map[string]string, resolve bool) error  

Parameters
Returns

nil on success, otherwise an error value

AddExitcallError

Add an error to the exit call.

Format 

func AddExitcallError(exitcall ExitcallHandle, level ErrorLevel, message string, mark_bt_as_error bool)  

Parameters

StartExitcall

Start an exit call to the specified backend as part of a business transaction.

Format

func StartExitcall(bt BtHandle, backend string) ExitcallHandle  

Parameters
Returns

An opaque handle to the exit call that was started. 

EndExitcall

Complete the exit call.

Format 

func EndExitcall(exitcall ExitcallHandle) 

Parameter

exitcall: Handle to the exit call being ended.

GetCRollupType

Specify how to roll up values for the metric over time.

Format 

func GetCRollupType(rollUp RollupType)

Parameters

GetCClusterRollupType

Specify how to aggregate metric values for the tier (a cluster of nodes).

Format 

func GetCClusterRollupType(rollUp ClusterRollupType)

Parameters

GetExitcall

Get a handle to an exit call associated with a guid via StoreExitcall.

Format 

func GetExitcall(guid string) ExitcallHandle 

Parameter

guid: The globally unique identifier that was passed to appd_exitcall_store().

Returns

The handle to the exit call associated with the given guid.

In the following cases the SDK logs a warning and returns a handle that you may safely use in other API functions but that will cause these functions to immediately return without doing anything:

GetExitcallCorrelationHeader

Get the header for correlating a business transaction. 

If a business transaction makes exit calls that you want to correlate across, retrieve the correlation header using this function and inject it into your exit call's payload.

The returned string is freed when the exit call ends. Do not free it yourself.

Format 

func GetExitcallCorrelationHeader(exitcall ExitcallHandle) string  

Parameter

exitcall: Handle to the exit call.

Returns

On success, returns a 7-bit ASCII string containing the correlation information. You can inject this string into the payload of the exit call. A downstream agent can then extract the header from that payload and continue the business transaction.

On error, returns the default header that prevents downstream business transaction detection.

SetExitcallDetails

Set the details string for an exit call. This can be used, for example, to add the SQL statement that a DB backend has executed as part of the exit call. This data is then visible in the exit calls details UI for the transaction snapshot.

Format 

func SetExitcallDetails(exitcall ExitcallHandle, details string) error  

Parameters
Returns

Nil on success, otherwise an error value

StoreExitcall

Store an exit call handle in a global registry for later retrieval with GetExitcall. This is useful when you need to start and end a call in separate places, and it is difficult to pass the handle through the parts of the code that need it.

The handle is removed when the exit call, or the BT containing it, ends.

Format 

func StoreExitcall(exitcall ExitcallHandle, guid string)  

Parameters

Example 

ExitcallHandle ec = StartExitcall(bt, "authdb");
StoreExitcall(ec, "login-exit");