forked from instana/go-sensor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eum.go
48 lines (37 loc) · 1.11 KB
/
eum.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// (c) Copyright IBM Corp. 2021
// (c) Copyright Instana Inc. 2018
package instana
import (
"bytes"
"io/ioutil"
"sort"
"strings"
)
const eumTemplate string = "eum.js"
// EumSnippet generates javascript code to initialize JavaScript agent
//
// Deprecated: this snippet is outdated and this method will be removed in
// the next major version. To learn about the way to install Instana EUM snippet
// please refer to https://docs.instana.io/products/website_monitoring/#installation
func EumSnippet(apiKey string, traceID string, meta map[string]string) string {
if len(apiKey) == 0 || len(traceID) == 0 {
return ""
}
b, err := ioutil.ReadFile(eumTemplate)
if err != nil {
return ""
}
snippet := strings.Replace(string(b), "$apiKey", apiKey, -1)
snippet = strings.Replace(snippet, "$traceId", traceID, -1)
var keys []string
for k := range meta {
keys = append(keys, k)
}
sort.Strings(keys)
var metaBuffer bytes.Buffer
for _, k := range keys {
metaBuffer.WriteString("ineum('meta','" + k + "','" + meta[k] + "');")
}
snippet = strings.Replace(snippet, "$meta", metaBuffer.String(), -1)
return snippet
}