-
Notifications
You must be signed in to change notification settings - Fork 853
/
otel_constants.go
176 lines (157 loc) · 6.51 KB
/
otel_constants.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package azcosmos
import (
"fmt"
"net/url"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/tracing"
)
const (
otelSpanNameCreateDatabase = "create_database"
otelSpanNameReadDatabase = "read_database"
otelSpanNameDeleteDatabase = "delete_database"
otelSpanNameQueryDatabases = "query_databases"
otelSpanNameReadThroughputDatabase = "read_database_throughput"
otelSpanNameReplaceThroughputDatabase = "replace_database_throughput"
otelSpanNameCreateContainer = "create_container"
otelSpanNameReadContainer = "read_container"
otelSpanNameDeleteContainer = "delete_container"
otelSpanNameReplaceContainer = "replace_container"
otelSpanNameQueryContainers = "query_containers"
otelSpanNameReadThroughputContainer = "read_container_throughput"
otelSpanNameReaplaceThroughputContainer = "replace_container_throughput"
otelSpanNameExecuteBatch = "execute_batch"
otelSpanNameCreateItem = "create_item"
otelSpanNameReadItem = "read_item"
otelSpanNameDeleteItem = "delete_item"
otelSpanNameReplaceItem = "replace_item"
otelSpanNameUpsertItem = "upsert_item"
otelSpanNamePatchItem = "patch_item"
otelSpanNameQueryItems = "query_items"
)
type span struct {
name string
options runtime.StartSpanOptions
}
func getSpanNameForClient(endpoint *url.URL, operationType operationType, resourceType resourceType, id string) (span, error) {
var spanName string
if resourceType == resourceTypeDatabase && operationType == operationTypeQuery {
spanName = otelSpanNameQueryDatabases
}
if spanName == "" {
return span{}, fmt.Errorf("undefined telemetry span for operationType %v and resourceType %v", operationType, resourceType)
}
return span{name: fmt.Sprintf("%s %s", spanName, id), options: getSpanPropertiesForClient(endpoint, spanName)}, nil
}
func getSpanNameForDatabases(endpoint *url.URL, operationType operationType, resourceType resourceType, id string) (span, error) {
var spanName string
switch resourceType {
case resourceTypeDatabase:
switch operationType {
case operationTypeCreate:
spanName = otelSpanNameCreateDatabase
case operationTypeRead:
spanName = otelSpanNameReadDatabase
case operationTypeDelete:
spanName = otelSpanNameDeleteDatabase
}
case resourceTypeCollection:
if operationType == operationTypeQuery {
spanName = otelSpanNameQueryContainers
}
case resourceTypeOffer:
switch operationType {
case operationTypeRead:
spanName = otelSpanNameReadThroughputDatabase
case operationTypeReplace:
spanName = otelSpanNameReplaceThroughputDatabase
}
}
if spanName == "" {
return span{}, fmt.Errorf("undefined telemetry span for operationType %v and resourceType %v", operationType, resourceType)
}
return span{name: fmt.Sprintf("%s %s", spanName, id), options: getSpanPropertiesForDatabase(endpoint, spanName, id)}, nil
}
func getSpanNameForContainers(endpoint *url.URL, operationType operationType, resourceType resourceType, database string, id string) (span, error) {
var spanName string
switch resourceType {
case resourceTypeCollection:
switch operationType {
case operationTypeCreate:
spanName = otelSpanNameCreateContainer
case operationTypeRead:
spanName = otelSpanNameReadContainer
case operationTypeDelete:
spanName = otelSpanNameDeleteContainer
case operationTypeReplace:
spanName = otelSpanNameReplaceContainer
case operationTypeBatch:
spanName = otelSpanNameExecuteBatch
}
case resourceTypeOffer:
switch operationType {
case operationTypeRead:
spanName = otelSpanNameReadThroughputContainer
case operationTypeReplace:
spanName = otelSpanNameReaplaceThroughputContainer
}
}
if spanName == "" {
return span{}, fmt.Errorf("undefined telemetry span for operationType %v and resourceType %v", operationType, resourceType)
}
return span{name: fmt.Sprintf("%s %s", spanName, id), options: getSpanPropertiesForContainer(endpoint, spanName, database, id)}, nil
}
func getSpanNameForItems(endpoint *url.URL, operationType operationType, database string, id string) (span, error) {
var spanName string
switch operationType {
case operationTypeCreate:
spanName = otelSpanNameCreateItem
case operationTypeRead:
spanName = otelSpanNameReadItem
case operationTypeDelete:
spanName = otelSpanNameDeleteItem
case operationTypeReplace:
spanName = otelSpanNameReplaceItem
case operationTypeUpsert:
spanName = otelSpanNameUpsertItem
case operationTypePatch:
spanName = otelSpanNamePatchItem
case operationTypeQuery:
spanName = otelSpanNameQueryItems
}
if spanName == "" {
return span{}, fmt.Errorf("undefined telemetry span for operationType %v and resourceType %v", operationType, resourceTypeDocument)
}
return span{name: fmt.Sprintf("%s %s", spanName, id), options: getSpanPropertiesForContainer(endpoint, spanName, database, id)}, nil
}
func getSpanPropertiesForClient(endpoint *url.URL, operationName string) runtime.StartSpanOptions {
return runtime.StartSpanOptions{Attributes: []tracing.Attribute{
{Key: "db.system", Value: "cosmosdb"},
{Key: "db.cosmosdb.connection_mode", Value: "gateway"},
{Key: "db.operation.name", Value: operationName},
{Key: "server.address", Value: endpoint.Hostname()},
{Key: "server.port", Value: endpoint.Port()},
}}
}
func getSpanPropertiesForDatabase(endpoint *url.URL, operationName string, id string) runtime.StartSpanOptions {
return runtime.StartSpanOptions{Attributes: []tracing.Attribute{
{Key: "db.system", Value: "cosmosdb"},
{Key: "db.cosmosdb.connection_mode", Value: "gateway"},
{Key: "db.namespace", Value: id},
{Key: "db.operation.name", Value: operationName},
{Key: "server.address", Value: endpoint.Hostname()},
{Key: "server.port", Value: endpoint.Port()},
}}
}
func getSpanPropertiesForContainer(endpoint *url.URL, operationName string, database string, id string) runtime.StartSpanOptions {
return runtime.StartSpanOptions{Attributes: []tracing.Attribute{
{Key: "db.system", Value: "cosmosdb"},
{Key: "db.cosmosdb.connection_mode", Value: "gateway"},
{Key: "db.namespace", Value: database},
{Key: "db.collection.name", Value: id},
{Key: "db.operation.name", Value: operationName},
{Key: "server.address", Value: endpoint.Hostname()},
{Key: "server.port", Value: endpoint.Port()},
}}
}