You need to enable JavaScript to run this app.
Torch Log Service

Torch Log Service

Copy page
Download PDF
Go SDK
Using the Go SDK to send logs to Kafka
Copy page
Download PDF
Using the Go SDK to send logs to Kafka
TLS supports delivering logs to Kafka via the SDK. This document demonstrates, with example code, how to send logs to Kafka using the Go SDK.​
Prerequisites​
  • The TLS Go SDK has been installed. For more information, see Install Go SDK.​
  • The following commands have been executed to install the proto dependencies.​
  • ​
    go get -u github.com/gogo/protobuf/proto​
    ​
  • The VOLCENGINE_ACCESS_KEY_ID and other environment variables have been added. For information on how to configure environment variables, please refer to Configure authentication information.​
warning​
It is recommended to use environment variables to dynamically obtain Volcano Engine keys and other authentication information to avoid data security risks caused by hardcoding the AccessKey.​
Scenario description​
This document demonstrates, using sample code, how to use the GO SDK to create a configuration for delivering logs to Kafka in a specified Project. For related precautions and cost information, please refer to Overview.​
Example code​
​
package demo​
​
import (​
"github.com/volcengine/volc-sdk-golang/service/tls"​
"os"​
"time"​
)​
​
func CreateShipperKafkaDemo() (*tls.CreateShipperResponse, error) {​
// When initializing the client, it's recommended to dynamically obtain the Volcano Engine key and other authentication information through environment variables to avoid data security risks caused by hard-coding the AccessKey. For detailed instructions, see https://www.volcengine.com/docs/6470/1166455.​
// When using STS, both ak and sk use temporary keys and set VOLCENGINE_TOKEN; when not using STS, the VOLCENGINE_TOKEN part is passed empty.​
client := tls.NewClient(os.Getenv("VOLCENGINE_ENDPOINT"), os.Getenv("VOLCENGINE_ACCESS_KEY_ID"), os.Getenv("VOLCENGINE_ACCESS_KEY_SECRET"), os.Getenv("VOLCENGINE_TOKEN"), os.Getenv("VOLCENGINE_REGION"))​
//Create a data delivery configuration.​
//For a description of the CreateShipper API request parameters, see https://www.volcengine.com/docs/6470/1333747.​
createShipperRes, err := client.CreateShipper(&tls.CreateShipperRequest{​
TopicId: "c7****",​
ShipperName: "testship",​
ShipperType: "kafka",​
ShipperStartTime: int(time.Now().UnixMilli()),​
ShipperEndTime: int(time.Now().UnixMilli()) + 3600*1000,​
KafkaShipperInfo: &tls.KafkaShipperInfo{​
Instance: "kafka-cnngbnntswg1****",​
KafkaTopic: "topic-c",​
Compress: "none",​
},​
ContentInfo: &tls.ContentInfo{​
Format: "json",​
JsonInfo: &tls.JsonInfo{​
Keys: []string{"__content__", "__source__", "__path__"},​
Enable: true,​
Escape: true,​
},​
},​
})​
​
if err != nil {​
return nil, err​
}​
​
return createShipperRes, nil​
}​
​
Related documentation​
  • After you send an API request through the SDK, you will receive a response from the server. If the response contains a status code other than 200, it means the API call has failed. You can refer to the documentation for each API to view the corresponding error code information.​
  • The API interfaces involved in this example are as follows. You can refer to the API documentation to view detailed information about the corresponding interface.​
  • ​
    API​
    Description​
    Call the CreateShipper API to create a delivery configuration.​
    Call the DeleteShipper API to delete the specified delivery configuration.​
    Call the ModifyShipper API to modify the specified delivery configuration.​
    Call the DescribeShipper API to obtain detailed information about the delivery configuration.​
    Call the DescribeShippers API to obtain the list of delivery configurations.​
    ​
​
Last updated: 2025.10.11 16:44:08