監視執行

Go Collector 提供 支援的技術的自動化程式碼檢測、Go 服務的零配置性能監視,以及所有系統中要求的端對端追蹤。

支援

支援的執行時期

  • Go 1.9 版或更新版本,適用於 1.47.0 之前的 Go 收集器版本
  • Go 1.13 版或更新版本 (適用於 Go Collector 1.47.0 版或更新版本)

支援的架構及程式庫

為了避免新增不必要的相依關係, Instana 主要 github.com/instana/go-sensor 模組僅為 Go 標準程式庫中的套件提供檢測。 協力廠商套件檢測是以在 github.com/instana/go-sensor/instrumentation/... 中找到的個別模組來提供,且需要個別新增至 go.mod

附註: 追蹤連續性 不適用於資料庫和記載程式庫。

HTTP

目標程式庫 版本 檢測套件 版本 追蹤連續性
net/http github.com/instana/go-sensor 1.51.0
github.com/labstack/echo 4.9.0 github.com/instana/go-sensor/instrumentation/instaecho 1.10.0
github.com/gin-gonic/gin 1.9.1 github.com/instana/go-sensor/instrumentation/instagin 1.9.0
github.com/gorilla/mux 1.8.0 github.com/instana/go-sensor/instrumentation/instamux 1.9.0
github.com/julienschmidt/httprouter 1.3.0 github.com/instana/go-sensor/instrumentation/instahttprouter 1.7.0
github.com/gofiber/fiber 2.49.2 github.com/instana/go-sensor/instrumentation/instafiber 0.4.0
github.com/beego/beego 2.1.3 github.com/instana/go-sensor/instrumentation/instabeego 0.1.0

RPC

目標程式庫 版本 檢測套件 版本 追蹤連續性
google.golang.org/grpc 1.53.0 github.com/instana/go-sensor/instrumentation/instagrpc 1.8.0

資料庫

目標程式庫 版本 檢測套件 版本
database/sql github.com/instana/go-sensor 1.51.0
go.mongodb.org/mongo-driver 1.7.2 github.com/instana/go-sensor/instrumentation/instamongo 1.7.0
jackc/pgx 4.14.1 github.com/instana/go-sensor/instrumentation/instapgx 0.8.0
go-redis 9.0.2 github.com/instana/go-sensor/instrumentation/instaredis 2.3.0
redigo 1.8.8 github.com/instana/go-sensor/instrumentation/instaredigo 0.8.0
gorm 1.25.0 github.com/instana/go-sensor/instrumentation/instagorm 1.2.0

傳訊

目標程式庫 版本 檢測套件 版本 追蹤連續性
cloud.google.com/go/pubsub 1.27.1 github.com/instana/go-sensor/instrumentation/cloud.google.com/go/pubsub 1.10.0
github.com/Shopify/sarama 1.19.0 github.com/instana/go-sensor/instrumentation/instasarama 1.13.0
github.com/streadway/amqp 1.0.0 github.com/instana/go-sensor/instrumentation/instaamqp 0.8.0
github.com/rabbitmq/amqp091-go 1.5.0 github.com/instana/go-sensor/instrumentation/instaamqp091 0.6.0

GraphQL

目標程式庫 版本 檢測套件 版本 追蹤連續性
graphql-go/graphql 0.8.1 github.com/instana/go-sensor/instrumentation/instagraphql 1.4.0

其他

目標程式庫 版本 檢測套件 版本 追蹤連續性
cloud.google.com/go/storage 1.27.0 github.com/instana/go-sensor/instrumentation/cloud.google.com/go/storage 1.10.0
github.com/aws/aws-sdk-go 1.44.209 github.com/instana/go-sensor/instrumentation/instaawssdk 1.11.0
github.com/aws/aws-lambda-go 1.20.0 github.com/instana/go-sensor/instrumentation/instalambda 1.11.0
github.com/sirupsen/logrus 1.5.0 github.com/instana/go-sensor/instrumentation/instalogrus 1.8.0
github.com/aws/aws-sdk-go-v2 1.21.0 github.com/instana/go-sensor/instrumentation/instaawsv2 0.1.0

執行時期度量

下列度量值已收集並顯示在「執行」程序儀表板上:

  • 記憶體用量
  • 資料堆使用情形
  • GC 活動
  • Goroutine

性能簽章

  • 呼叫
  • 回應時間
  • 調整

安裝

Instana Go 收集器的安裝是一個簡單的兩步驟程序。 首先,將 github.com/instana/go-sensor 模組新增至 go.mod 檔案:

go get github.com/instana/go-sensor

go-sensor 模組新增至應用程式相依關係之後,您可以使用 go-sensor 模組來 檢測 應用程式碼。 如需相關資訊,請參閱 安裝

附註: 從 1.53.0版開始, Go 收集器在內部使用 fsm v1.0.1 。 如果您在專案中使用 v1 之前的 fsm 版本,則可能會遇到編譯問題,且您需要將 fsm 版本更新為 v1。

追蹤器日誌

Go Collector 使用分層日誌程式來記載內部錯誤及診斷資訊。 預設 logger.Logger 使用以 log.Lstdflags 配置的 log.Logger 作為後端,並將訊息寫入 os.Stderr。 依預設,除非設定環境變數 INSTANA_DEBUG ,否則此日誌程式只會印出 ERROR 層次訊息。

若要變更執行時期的最小記載層次,建議配置並注入 instana.LeveledLogger實例:

l := logger.New(log.New(os.Stderr, "", os.Lstdflags))
instana.SetLogger(l)

// ...

l.SetLevel(logger.WarnLevel)

logger.LeveledLogger 介面由 github.com/sirupsen/logrusgo.uber.org/zap之類的熱門記載程式庫實作,因此可以使用它們作為取代項目。

或者,從 Go 感應器 1.39.0 版開始,可以使用 INSTANA_LOG_LEVEL 環境變數來設定記載層次。

附註: INSTANA_DEBUG 環境變數的值不會影響自訂日誌程式。 您需要明確地檢查是否已設定它,並在配置日誌程式時啟用除錯記載:

import (
	instana "github.com/instana/go-sensor"
	"github.com/sirupsen/logrus"
)

func main() {
	// initialize Instana sensor
	instana.InitSensor(&instana.Options{Service: SERVICE})

	// initialize and configure the logger
	logger := logrus.New()
	logger.Level = logrus.InfoLevel

	// check if INSTANA_DEBUG is set and set the log level to DEBUG if needed
	if _, ok := os.LookupEnv("INSTANA_DEBUG"); ok {
		logger.Level = logrus.DebugLevel
	}

	// use logrus to log the Instana Go Collector messages
	instana.SetLogger(logger)

	// ...
}

平台

Go 收集器支援無伺服器模式,當它取代主機代理程式時,它會將度量值及追蹤資料傳送至無伺服器接收器端點。 若要將收集器切換至無伺服器模式,請將 INSTANA_ENDPOINT_URL 環境變數設為 Instana 安裝架構的無伺服器接收器 URL ,並透過 INSTANA_AGENT_KEY提供代理程式金鑰。 請參閱 無伺服器監視 一節,以瞭解無伺服器模式中可用的其他配置選項。

AWS Fargate

Instana Go 收集器會在以無伺服器模式執行時,自動偵測服務是否在 AWS Fargate 上執行。

Google Cloud 執行

Instana Go 收集器會自動偵測服務是否在 Google Cloud 以無伺服器模式執行時執行。

AWS Lambda

Instana Go 收集器支援從 v1.23.0開始追蹤以 Go 撰寫的 AWS Lambda 函數。 需要使用 github.com/instana/go-sensor/instrumentation/instalambda 套件來檢測處理程式,才能收集並傳送追蹤資料。 如需詳細資料,請參閱 AWS Lambda go 文件。

Azure 功能

Instana Go 收集器支援追蹤以 Go 撰寫的 Azure 函數。 需要使用 github.com/instana/go-sensor/instrumentation/instaazurefunction 套件來檢測處理程式,以收集並傳送追蹤資料。 如需相關資訊,請參閱 Azure Functions Tracing for Go

Kubernetes & OpenShift

如果您的 Go 應用程式及 Instana 代理程式在 Kubernetes 叢集裡執行,請參閱 Kubernetes 網路存取 上的說明文件,以取得此設定中必要配置的相關資訊。

配置

Go 收集器接受兩種格式的配置: 在應用程式碼內透過 instana.Options 配置物件或透過 環境變數。 應用程式內配置優先於環境變數,但下列設定除外:

  • INSTANA_SERVICE_NAME 容許置換程式碼中設定的服務名稱
  • INSTANA_PROCESS_NAME 容許置換代表 Go 處理程序之基礎架構實體的名稱。
  • 即使應用程式碼配置定義較高的記載層次, INSTANA_DEBUG 仍會啟用除錯日誌
  • INSTANA_AUTO_PROFILE 使用 AutoProfile™ 啟用連續側寫
  • INSTANA_LOG_LEVEL 容許指定記載層次。 可能的值為 debugerrorwarninfo。 如果設定,則 INSTANA_DEBUG 環境變數優先
  • INSTANA_KAFKA_HEADER_FORMAT 可讓使用者指定 Instana 所傳播 Kafka 標頭的格式。 可能的值為 binary (舊式)、 string (新格式) 及 both

如需詳細資訊,請參閱 配置頁面

Instana AutoProfile™

設定檔對於尋找程式碼層次的效能熱點和瓶頸非常重要。 它們有助於減少資源消耗和改善效能。

AutoProfile™ 會產生程序設定檔並將其報告給 Instana。 與開發時間及隨需應變側寫程式不同的是,使用者必須手動起始側寫, AutoProfile™ 會自動排程並持續執行適用於重要正式作業環境的側寫。

啟用 instana.InitSensor(opt)中的 AutoProfile™ 新增 EnableAutoProfile: true 選項。 如需詳細指示,請參閱 github.com/instana/go-sensor。 如果您需要針對使用 Instana 檢測的應用程式啟用側寫,而不變更 instana.InitSensor() 配置,請設定 INSTANA_AUTO_PROFILE=true env 變數。 請注意,此值具有優先順序,並且會置換從應用程式碼內部停用側寫的任何嘗試。

如需相關資訊,請參閱我們的 Instana AutoProfile™ 文件。

疑難排解

過時 Go 執行時期

監視問題類型: outdated_go_runtime

若要解決此問題,請將 Go 執行時期版本更新為最新版本。

另請參閱