This repository has been archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
integration.go
71 lines (63 loc) · 2.17 KB
/
integration.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package redis
import (
"bytes"
"fmt"
"strconv"
"strings"
"github.com/thundra-io/thundra-lambda-agent-go/v2/application"
"github.com/thundra-io/thundra-lambda-agent-go/v2/config"
"github.com/thundra-io/thundra-lambda-agent-go/v2/constants"
"github.com/thundra-io/thundra-lambda-agent-go/v2/tracer"
)
func BeforeCall(span *tracer.RawSpan, host string, port string, commandName string, command string) {
span.ClassName = constants.ClassNames["REDIS"]
span.DomainName = constants.DomainNames["CACHE"]
if len(commandName) == 0 {
commandName = strings.Split(command, " ")[0]
}
commandName = strings.ToUpper(commandName)
// Set span tags
tags := map[string]interface{}{
constants.SpanTags["OPERATION_TYPE"]: constants.RedisCommandTypes[commandName],
constants.DBTags["DB_INSTANCE"]: host,
constants.DBTags["DB_STATEMENT_TYPE"]: commandName,
constants.DBTags["DB_TYPE"]: "redis",
constants.RedisTags["REDIS_HOST"]: host,
constants.RedisTags["REDIS_COMMAND_TYPE"]: commandName,
}
tags[constants.SpanTags["TRIGGER_DOMAIN_NAME"]] = constants.AwsLambdaApplicationDomain
tags[constants.SpanTags["TRIGGER_CLASS_NAME"]] = constants.AwsLambdaApplicationClass
tags[constants.SpanTags["TRIGGER_OPERATION_NAMES"]] = []string{application.FunctionName}
tags[constants.SpanTags["TOPOLOGY_VERTEX"]] = true
if !config.MaskRedisCommand {
tags[constants.DBTags["DB_STATEMENT"]] = command
tags[constants.RedisTags["REDIS_COMMAND"]] = command
}
span.Tags = tags
}
func AfterCall(span *tracer.RawSpan, command string) {
if !config.MaskRedisCommand {
span.Tags[constants.DBTags["DB_STATEMENT"]] = command
span.Tags[constants.RedisTags["REDIS_COMMAND"]] = command
}
}
func GetRedisCommand(commandName string, args ...interface{}) string {
var b bytes.Buffer
b.WriteString(commandName)
for _, arg := range args {
b.WriteString(" ")
switch arg := arg.(type) {
case string:
b.WriteString(arg)
case int:
b.WriteString(strconv.Itoa(arg))
case int32:
b.WriteString(strconv.FormatInt(int64(arg), 10))
case int64:
b.WriteString(strconv.FormatInt(arg, 10))
case fmt.Stringer:
b.WriteString(arg.String())
}
}
return b.String()
}