mirror of
https://dev.azure.com/schwarzit/schwarzit.stackit-public/_git/audit-go
synced 2026-02-07 16:47:24 +00:00
Add telemetry data to cloud event properties
This commit is contained in:
parent
26673e8962
commit
18a6f6f07d
2 changed files with 40 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"context"
|
||||
"dev.azure.com/schwarzit/schwarzit.stackit-public/audit-go.git/telemetry"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
|
@ -190,6 +191,21 @@ func send(
|
|||
applicationAttributes["cloudEvents:tracestate"] = *cloudEvent.TraceState
|
||||
}
|
||||
|
||||
// Telemetry
|
||||
applicationAttributes["cloudEvents:sdklanguage"] = "go"
|
||||
auditGoVersion := telemetry.AuditGoVersion
|
||||
if auditGoVersion != "" {
|
||||
applicationAttributes["cloudEvents:sdkversion"] = auditGoVersion
|
||||
}
|
||||
auditGoGrpcVersion := telemetry.AuditGoGrpcVersion
|
||||
if auditGoGrpcVersion != "" {
|
||||
applicationAttributes["cloudEvents:sdkgrpcversion"] = auditGoGrpcVersion
|
||||
}
|
||||
auditGoHttpVersion := telemetry.AuditGoHttpVersion
|
||||
if auditGoHttpVersion != "" {
|
||||
applicationAttributes["cloudEvents:sdkhttpversion"] = auditGoHttpVersion
|
||||
}
|
||||
|
||||
return (*messagingApi).Send(
|
||||
ctx,
|
||||
topic,
|
||||
|
|
|
|||
24
telemetry/telemetry.go
Normal file
24
telemetry/telemetry.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package telemetry
|
||||
|
||||
import (
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
var AuditGoVersion = GetLibVersion("dev.azure.com/schwarzit/schwarzit.stackit-public/audit-go.git")
|
||||
var AuditGoGrpcVersion = GetLibVersion("dev.azure.com/schwarzit/schwarzit.stackit-public/audit-go-grpc.git")
|
||||
var AuditGoHttpVersion = GetLibVersion("dev.azure.com/schwarzit/schwarzit.stackit-public/audit-go-http.git")
|
||||
|
||||
func GetLibVersion(libName string) string {
|
||||
undefined := ""
|
||||
|
||||
bi, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return undefined
|
||||
}
|
||||
for _, dep := range bi.Deps {
|
||||
if dep.Path == libName {
|
||||
return dep.Version
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
Loading…
Reference in a new issue