forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql_test.go
64 lines (55 loc) · 2.4 KB
/
sql_test.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
// Copyright 2019, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http:https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package translator
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
semconventions "go.opentelemetry.io/collector/translator/conventions"
)
func TestClientSpanWithStatementAttribute(t *testing.T) {
attributes := make(map[string]string)
attributes[semconventions.AttributeComponent] = "db"
attributes[semconventions.AttributeDBType] = "sql"
attributes[semconventions.AttributeDBInstance] = "customers"
attributes[semconventions.AttributeDBStatement] = "SELECT * FROM user WHERE user_id = ?"
attributes[semconventions.AttributeDBUser] = "readonly_user"
attributes[semconventions.AttributeDBURL] = "mysql:https://db.example.com:3306"
attributes[semconventions.AttributeNetPeerName] = "db.example.com"
attributes[semconventions.AttributeNetPeerPort] = "3306"
filtered, sqlData := makeSQL(attributes)
assert.NotNil(t, filtered)
assert.NotNil(t, sqlData)
w := testWriters.borrow()
if err := w.Encode(sqlData); err != nil {
assert.Fail(t, "invalid json")
}
jsonStr := w.String()
testWriters.release(w)
assert.True(t, strings.Contains(jsonStr, "mysql:https://db.example.com:3306/customers"))
}
func TestClientSpanWithHttpComponent(t *testing.T) {
attributes := make(map[string]string)
attributes[semconventions.AttributeComponent] = semconventions.ComponentTypeHTTP
attributes[semconventions.AttributeDBType] = "sql"
attributes[semconventions.AttributeDBInstance] = "customers"
attributes[semconventions.AttributeDBStatement] = "SELECT * FROM user WHERE user_id = ?"
attributes[semconventions.AttributeDBUser] = "readonly_user"
attributes[semconventions.AttributeDBURL] = "mysql:https://db.example.com:3306"
attributes[semconventions.AttributeNetPeerName] = "db.example.com"
attributes[semconventions.AttributeNetPeerPort] = "3306"
filtered, sqlData := makeSQL(attributes)
assert.NotNil(t, filtered)
assert.Nil(t, sqlData)
}