Search…
Go
OpenTelemetry based Go module enhanced for maximum security.
Traceable’s Go module is based on OpenTelemetery and enhances the spans within a Trace with security-focused attributes. Traceable’s module can capture all the traffic that flows through your application including request and response headers along with the body of the request and response.

Prerequisite

Supported Frameworks

Servers
Clients
Net HTTP net/http
Net Http net/http
GRPC Server google.golang.org/grpc
GRPC Client google.golang.org/grpc
Gorilla Mux github.com/gorilla/mux
SQL database/sql

Download and configure

1
# go get -u github.com/hypertrace/goagent
Copied!

Configure Go module

You can configure Traceable’s Go module with a few lines as shown below. Following is a snippet with only a few configurations in the main.go file.
1
// loads the config from the config file tbd.json and env vars
2
cfg := config.Load()
3
4
// overrides statically the service name
5
cfg.ServiceName = config.String("myservice")
6
cfg.DataCapture.HTTPHeaders.Request = config.Bool(true)
Copied!
You can define the configuration variables in a JSON or YAML file, for example, config.yml. Alternatively, you can use environment variables to define the configuration variables or in the code as shown above. In the above snippet:
    myservice is the name of the service with which you would want it to be identified on Traceable’s Dashboard
    DataCapture.HTTPHeaders.Request is set to true. This captures the HTTP request headers.
You can overwrite the location of the configuration JSON or YAML file by providing the path in the environment variable HT_CONFIG_FILE. The path of the configuration file can also be set in the code as shown in the snippet below:
1
// loads the config from the specified file and env vars
2
cfg := config.LoadFromFile("path/to/config.yml")
3
...
Copied!
The following table lists the environment variables. The environment variable can also be used to overwrite the default values. For example, you can set the environment variable toHT_DATA_CAPTURE_HTTP_HEADERS_RESPONSE=false to overwrite the value set in the configuration file or through the code. To check the entire list of environment variables, refer to the Github link.
Environment variable
Description
HT_SERVICE_NAME
Identifies the service or process on Traceable’s dashboard.
HT_REPORTING_ADDRESS
The address of the collector where traces are reported, for example, api.traceable.ai
HT_REPORTING_SECURE
When true, connect to endpoints over TLS.
HT_REPORTING_TOKEN
Your token to access Traceable API. You can generate this token from Traceable’s onboarding page or reach out to Traceable’s support team for generating the token.
HT_REPORTING_OPA_ADDRESS
The address OPA host to fetch the blocking rules, for example, http://opa.traceable.ai:8181/
HT_REPORTING_OPA_POLL_PERIOD_SECONDS
The poll period in seconds to query the OPA service.
HT_DATA_CAPTURE_HTTP_BODY_REQUEST
When set to true, capture the body of the HTTP request
HT_DATA_CAPTURE_HTTP_BODY_RESPONSE
When set to true, captures the body of the HTTP response
HT_DATA_CAPTURE_HTTP_HEADERS_REQUEST
When set to true, captures the header of the HTTP request
HT_DATA_CAPTURE_HTTP_HEADERS_RESPONSE
When set to true, captures the header of the HTTP response
HT_DATA_CAPTURE_RPC_METADATA_REQUEST
When set to true, captures the RPC metadata of the request
HT_DATA_CAPTURE_RPC_METADATA_RESPONSE
When set to true, captures the RPC metadata of the response
HT_DATA_CAPTURE_RPC_BODY_REQUEST
When set to true, captures the RPC body of the request
HT_DATA_CAPTURE_RPC_BODY_RESPONSE
When set to true, captures the RPC body of the response

Sample YAML file

Following is a sample YAML file to configure the various values like collector and OPA address. You can configure based on your environment’s requirement.
1
reporting:
2
endpoint: <collector_url_and_port>
3
secure: true
4
opa:
5
endpoint: <opa_url_and_port>
6
pollPeriodSeconds: 30
7
dataCapture:
8
httpHeaders:
9
request: true
10
response: true
11
httpBody:
12
request: true
13
response: true
14
rpcMetadata:
15
request: true
16
response: true
17
rpcBody:
18
request: true
19
response: true
Copied!
The configuration default values are defined in the defaults.go file.

Verify deployment

To verify the deployment of the Go agent, log into your Traceable Dashboard and click on Services. If the deployment was successful, you will see your service listed under the Name column.
Last modified 2mo ago