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.
The Go SDK defines these opaque types:
BtHandle: A handle to an active business transactionExitcallHandle: A handle to an active exit callThe 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:
AppName: Name of the business application to which this node belongs. TierName: Name of the tier to which this node belongs. A tier is a group of identical or similar nodes. An originating tier is the tier that receives the first request of a business transaction. A downstream tier is a tier that is called from another tier, thus continuing a business transaction.NodeName: The monitored application server to be monitored by this agent.Controller: Connection settings for the Controller. This struct is defined as:
type Controller struct {
Host string
Port uint16
Account, AccessKey string
UseSSL bool
HTTPProxy HTTPProxy
CertificateFile
CertificateDir
} |
The Controller struct contains these fields:
Host: Controller host.Port: Controller port; defaults to 8080.Account: Name of your Access_key: Key to your UseSSL: Enable SSL communication with the controller; the default is false. Set to true to enable. If you set UseSSL to true, the default certificate, ca-bundle.crt, is used. To use your own certificate, specify your certificate file and directory in the CertificateFile and CertificateDir parameters.HTTPProxy: If the agent needs to connect to the Controller via a local HTTP proxy, use this struct to specify connection settings for the proxy. CertificateFile : The file name of the SSL certificate.CertificateDir – The directory where the certificate is located.InitTimeoutMs: The initialization function, InitSDK relies on the Controller configuration to start business transactions. To prevent the initialization function from blocking your application, you can use this setting. It lets you instruct InitSDK whether to wait for the Controller configuration and if so how long to wait before starting business transactions. Valid values are:
N: Wait for up to N milliseconds for the Controller configuration.
0: Do not wait for the Controller configuration. This is the default.
-1: Wait indefinitely until the Controller configuration is received by the agent.
Logging: Logging settings for the controller. This struct is defined as:
const (
APPD_LOG_LEVEL_DEFAULT LogLevel = iota
APPD_LOG_LEVEL_TRACE
APPD_LOG_LEVEL_DEBUG
APPD_LOG_LEVEL_INFO
APPD_LOG_LEVEL_WARN
APPD_LOG_LEVEL_ERROR
APPD_LOG_LEVEL_FATAL
)
type LoggingConfig struct {
BaseDir string
MinimumLevel LogLevel
MaxNumFiles uint
MaxFileSizeBytes uint
} |
The Logging struct contains these fields:
BaseDir: The absolute path to the directory where log files are written. If left empty, the default is /tmp/appd.MinimumLevel: One of the APPD_LOG_LEVEL_xxx constants that are shown above. The default is APPD_LOG_LEVEL_INFO.MaxNumFiles: The maximum number of logging files to store on disk. Once this maximum is hit, older logs are rotated out.MaxFileSizeBytes: The maximum size of the log files before they are rotated.UseConfigFromEnv: Set to true if you want the SDK to check for any configuration environment variables and use those configuration values for initialization. Note that because this happens on initialization, the environment variable settings override the configuration you set in your program.EnvVarPrefix: If UseConfigFromEnv is set to true, use this property to specify the prefix to use for environment variable names. The default prefix is APPD_SDK.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:
Host: Hostname or IP address of the HTTP proxy serverPort: Port of the proxy serverUsername: Proxy server user namePasswordFile: Proxy server password fileYou 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:
AppName: Name of the business application to which this node belongs. TierName: Name of the tier to which this node belongs. A tier is a group of identical or similar nodes. An originating tier is the tier that receives the first request of a business transaction. A downstream tier is a tier that is called from another tier, thus continuing a business transaction.NodeName: The monitored application server to be monitored by this agent.Add application context to the configuration for a multi-tenant Controller.
func AddAppContextToConfig(cfg *Config, context string, contextCfg *ContextConfig) error
cfg: context: A unique identifier used to refer to this context. contextCfg: A Initialize the Go SDK. An instrumented application must call this function once, preferably during application startup.
func InitSDK(cfg *Config) error
cfg: configuration settings that enable communication between the agent and the Controller.
nil on success, otherwise an error value
Stop the Go SDK. Ends all active business transactions for this agent and stops agent metric reporting to the Controller.
func TerminateSDK()
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.
func StartBT(name, correlation_header string) BtHandle
name: The name for the business transaction. In the case of a continuing transaction in the current business application with a valid correlation header, the SDK uses the name from the header. Do not use the following characters in transaction names: { } [ ] | & ;correlation_header: A correlation header if this is a continuing transaction, else NULL. If specified, the correlation header has been generated by another agent and made available to this agent as a string. The correlation header provides information to enable this transaction to correlate with an upstream transaction.An opaque handle for the business transaction that was started.
Start a business transaction or continue an existing transaction in a multi-tenant Controller environment.
func StartBTWithAppContext(context, name, correlation_header string) BtHandle
context: The application context name that this business transaction belongs to.name: The name for the business transaction. In the case of a continuing transaction in the current business application with a valid correlation header, the SDK uses the name from the header. Do not use the following characters in transaction names: { } [ ] | & ;correlation_header: A correlation header if this is a continuing transaction, else NULL. If specified, the correlation header has been generated by another agent and made available to this agent as a string. The correlation header provides information to enable this transaction to correlate with an upstream transaction.End the given business transaction.
func EndBT(bt BtHandle)
bt: The handle to the business transaction to end.
Get a BT handle associated with the given guid by appd_bt_store.
func GetBT(guid string) BtHandle
guid: The globally unique identifier that was passed to appd_bt_store.
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:
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.
func IsBTSnapshotting(bt BtHandle) bool
bt: The handle to the business transaction to check for snapshotting.
true if the given business transaction is taking a snapshot. Otherwise, false.
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.
func SetBTURL(bt BtHandle, url string)
bt: The business transaction to add the user data to, if it is taking a snapshot.url: The value of the URL for the snapshot as 7-bit ASCII or UTF-8.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.
func StoreBT(bt BtHandle, guid string)
bt: The BT to store.guid: A globally unique identifier to associate with the given BT.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).
func AddBTError(bt BtHandle, level ErrorLevel, message string, mark_bt_as_error bool)
bt: The handle to the business transaction to which the error is added.level: The error level, from the following: APPD_LEVEL_NOTICE
APPD_LEVEL_WARNING
APPD_LEVEL_ERROR
message: Error message for this error.mark_bt_as_error: If true, the business transaction experiencing this error is marked as an error transaction. In this case, the business transaction is counted only as an error transaction. It is not also counted as a slow, very slow or stalled transaction, even if the transaction was also slow or stalled. If false, the business transaction is not marked as an error transaction.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.
func AddUserDataToBT(bt BtHandle, key, value string)
bt –The business transaction to add the user data to, if it's taking a snapshot.key – The name of the user data to add to the snapshot as 7-bit ASCII or UTF-8.value – The value of the user data to add to the snapshot as 7-bit ASCII or UTF-8.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.
func AddBackend(name, backendType string, identifyingProperties map[string]string, resolve bool) error
name: The name of the backend. Must be unique to the Go SDK instance.backendType: The type of the backend, from these options: APPD_BACKEND_HTTP
APPD_BACKEND_DB
APPD_BACKEND_CACHE
APPD_BACKEND_RABBITMQ
APPD_BACKEND_WEBSERVICE
APPD_BACKEND_JMS
identifyingProperties: A map of key/value pairs that contain the backend's identifying properties. The properties uniquely identify backend. In the Controller, these properties appear in the upper right panel of the backend dashboards. You must set at least one identifying property when you add a backend of one of the built-in exit call types. The valid properties vary per exit call type as indicated below.
| Exit Call Type | Valid Identifying Properties |
|---|---|
| "HOST", "PORT", "URL", "QUERY STRING" |
APPD_BACKEND_DB | "HOST", "PORT", "DATABASE", "VENDOR", "VERSION" |
APPD_BACKEND_CACHE | "SERVER POOL", "VENDOR" |
APPD_BACKEND_RABBITMQ | "HOST", "PORT", "ROUTING KEY", "EXCHANGE" |
APPD_BACKEND_WEBSERVICE | "SERVICE", "URL", "OPERATION", "SOAP ACTION", "VENDOR" |
APPD_BACKEND_JMS | "DESTINATION", "DESTINATIONTYPE", and "VENDOR" |
For example, a key PORT would have a value of 3304.
resolve: Set the property to false to prevent a downstream agent from resolving as this backend. For example, if you have Tier A connecting to uninstrumented Backend B, which routes to instrumented Tier C, the setting affects the flow map as follows:
True, the flow map will be A > C.
False, the flow map will be A > B > C.
nil on success, otherwise an error value
Add an error to the exit call.
func AddExitcallError(exitcall ExitcallHandle, level ErrorLevel, message string, mark_bt_as_error bool)
exitcall: Handle to the exit call.level: The level of this error, from the following: APPD_LEVEL_NOTICE
APPD_LEVEL_WARNING
APPD_LEVEL_ERROR
message: Error message for this error.mark_bt_as_error: If true, the business transaction making the exit call that is experiencing this error is marked as an error transaction. In this case, the business transaction is counted only as an error transaction. It is not also counted as a slow, very slow or stalled transaction, even if the transaction was also slow or stalled. If false, the business transaction is not marked as an error transaction.Start an exit call to the specified backend as part of a business transaction.
func StartExitcall(bt BtHandle, backend string) ExitcallHandle
bt: Handle to the business transaction making the exit call.backend:The destination backend of the exit call. An opaque handle to the exit call that was started.
Complete the exit call.
func EndExitcall(exitcall ExitcallHandle)
exitcall: Handle to the exit call being ended.
Specify how to roll up values for the metric over time.
func GetCRollupType(rollUp RollupType)
rollUp: The approach for rolling up metrics. The following roll-up options are valid: APPD_TIMEROLLUP_TYPE_AVERAGE: The average of all metric values across each node in the tier.APPD_TIMEROLLUP_TYPE_SUM: Sum of all reported values in the minute.APPD_TIMEROLLUP_TYPE_CURRENT: The last reported metric in the minute.Specify how to aggregate metric values for the tier (a cluster of nodes).
func GetCClusterRollupType(rollUp ClusterRollupType)
rollUp: The approach for rolling up metrics. The following roll-up options are valid: APPD_CLUSTERROLLUP_TYPE_INDIVIDUAL: The average of all metric values across each node in the tier.Get a handle to an exit call associated with a guid via StoreExitcall.
func GetExitcall(guid string) ExitcallHandle
guid: The globally unique identifier that was passed to appd_exitcall_store().
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:
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.
func GetExitcallCorrelationHeader(exitcall ExitcallHandle) string
exitcall: Handle to the exit call.
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.
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.
func SetExitcallDetails(exitcall ExitcallHandle, details string) error
exitcall: Handle to the exit call.details: An arbitrary string to add to the exit call.Nil on success, otherwise an error value
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.
func StoreExitcall(exitcall ExitcallHandle, guid string)
exitcall: The exit call to store.guid: A globally unique identifier to associate with the given call.Example
ExitcallHandle ec = StartExitcall(bt, "authdb"); StoreExitcall(ec, "login-exit"); |