-
Notifications
You must be signed in to change notification settings - Fork 415
/
op.go
191 lines (174 loc) · 3.71 KB
/
op.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023 Datadog, Inc.
package namingschema
import (
"fmt"
"strings"
)
type IntegrationType int
const (
// client/server
HTTPClient IntegrationType = iota
HTTPServer
GRPCClient
GRPCServer
GraphqlServer
TwirpClient
TwirpServer
// messaging
KafkaOutbound
KafkaInbound
GCPPubSubInbound
GCPPubSubOutbound
// cache
MemcachedOutbound
RedisOutbound
// db
ElasticSearchOutbound
MongoDBOutbound
CassandraOutbound
LevelDBOutbound
BuntDBOutbound
ConsulOutbound
VaultOutbound
)
func opV1(t IntegrationType) string {
switch t {
// Client/Server
case HTTPClient:
return "http.client.request"
case HTTPServer:
return "http.server.request"
case GRPCClient:
return "grpc.client.request"
case GRPCServer:
return "grpc.server.request"
case GraphqlServer:
return "graphql.server.request"
case TwirpClient:
return "twirp.client.request"
case TwirpServer:
return "twirp.server.request"
// Messaging
case KafkaOutbound:
return "kafka.send"
case KafkaInbound:
return "kafka.process"
case GCPPubSubInbound:
return "gcp.pubsub.process"
case GCPPubSubOutbound:
return "gcp.pubsub.send"
// Cache
case MemcachedOutbound:
return "memcached.command"
case RedisOutbound:
return "redis.command"
// Database
case ElasticSearchOutbound:
return "elasticsearch.query"
case MongoDBOutbound:
return "mongodb.query"
case CassandraOutbound:
return "cassandra.query"
case LevelDBOutbound:
return "leveldb.query"
case BuntDBOutbound:
return "buntdb.query"
case ConsulOutbound:
return "consul.query"
case VaultOutbound:
return "vault.query"
}
return ""
}
func opV0(t IntegrationType) string {
switch t {
case HTTPClient, HTTPServer:
return "http.request"
case GRPCClient:
return "grpc.client"
case GRPCServer:
return "grpc.server"
case GraphqlServer:
return "graphql.request"
case TwirpClient:
return "twirp.request"
case TwirpServer:
return "twirp.request"
case KafkaOutbound:
return "kafka.produce"
case KafkaInbound:
return "kafka.consume"
case GCPPubSubInbound:
return "pubsub.receive"
case GCPPubSubOutbound:
return "pubsub.publish"
case MemcachedOutbound:
return "memcached.query"
case RedisOutbound:
return "redis.command"
case ElasticSearchOutbound:
return "elasticsearch.query"
case MongoDBOutbound:
return "mongodb.query"
case CassandraOutbound:
return "cassandra.query"
case LevelDBOutbound:
return "leveldb.query"
case BuntDBOutbound:
return "buntdb.query"
case ConsulOutbound:
return "consul.command"
case VaultOutbound:
return "http.request"
}
return ""
}
func OpName(t IntegrationType) string {
switch GetVersion() {
case SchemaV1:
return opV1(t)
default:
return opV0(t)
}
}
func OpNameOverrideV0(t IntegrationType, overrideV0 string) string {
switch GetVersion() {
case SchemaV1:
return opV1(t)
default:
return overrideV0
}
}
func DBOpName(system string, overrideV0 string) string {
switch GetVersion() {
case SchemaV1:
return system + ".query"
default:
return overrideV0
}
}
func isMessagingSendOp(awsService, awsOperation string) bool {
s, op := strings.ToLower(awsService), strings.ToLower(awsOperation)
if s == "sqs" {
return strings.HasPrefix(op, "sendmessage")
}
if s == "sns" {
return op == "publish"
}
return false
}
func AWSOpName(awsService, awsOp, overrideV0 string) string {
switch GetVersion() {
case SchemaV1:
op := "request"
if isMessagingSendOp(awsService, awsOp) {
op = "send"
}
return fmt.Sprintf("aws.%s.%s", strings.ToLower(awsService), op)
default:
return overrideV0
}
}