mirror of
https://github.com/verssache/chatgpt-creator.git
synced 2026-05-16 21:59:33 +00:00
Initial commit: ChatGPT Account Registration Bot
This commit is contained in:
38
internal/util/trace.go
Normal file
38
internal/util/trace.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// MakeTraceHeaders generates Datadog-compatible trace headers.
|
||||
func MakeTraceHeaders() map[string]string {
|
||||
traceID := make([]byte, 16)
|
||||
rand.Read(traceID)
|
||||
spanID := make([]byte, 8)
|
||||
rand.Read(spanID)
|
||||
|
||||
traceIDHex := hex.EncodeToString(traceID)
|
||||
spanIDHex := hex.EncodeToString(spanID)
|
||||
|
||||
// traceparent: 00-{traceID}-{spanID}-01
|
||||
traceparent := fmt.Sprintf("00-%s-%s-01", traceIDHex, spanIDHex)
|
||||
|
||||
// tracestate: dd=t.dm:-1;t.tid:{first16ofTraceID};s:-1
|
||||
tracestate := fmt.Sprintf("dd=t.dm:-1;t.tid:%s;s:-1", traceIDHex[:16])
|
||||
|
||||
// x-datadog-trace-id: decimal conversion of last 16 hex chars (last 8 bytes)
|
||||
traceIDInt := new(big.Int).SetBytes(traceID[8:])
|
||||
// x-datadog-parent-id: decimal conversion of spanID
|
||||
spanIDInt := new(big.Int).SetBytes(spanID)
|
||||
|
||||
return map[string]string{
|
||||
"traceparent": traceparent,
|
||||
"tracestate": tracestate,
|
||||
"x-datadog-trace-id": traceIDInt.String(),
|
||||
"x-datadog-parent-id": spanIDInt.String(),
|
||||
"x-datadog-sampling-priority": "-1",
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user