Skip to content

Commit

Permalink
update test to match net scope
Browse files Browse the repository at this point in the history
  • Loading branch information
grcevski committed Apr 12, 2024
1 parent 634be15 commit 70b4747
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 44 deletions.
4 changes: 2 additions & 2 deletions internal/test/e2e/gin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
}()

// give time for auto-instrumentation to start up
time.Sleep(10 * time.Second)
time.Sleep(5 * time.Second)

resp, err := http.Get("http://localhost:8080/hello-gin")
if err != nil {
Expand All @@ -48,5 +48,5 @@ func main() {
_ = resp.Body.Close()

// give time for auto-instrumentation to report signal
time.Sleep(10 * time.Second)
time.Sleep(5 * time.Second)
}
30 changes: 0 additions & 30 deletions internal/test/e2e/gin/traces.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,6 @@
},
"schemaUrl": "https://opentelemetry.io/schemas/1.21.0",
"scopeSpans": [
{
"scope": {
"name": "go.opentelemetry.io/auto/github.com/gin-gonic/gin",
"version": "v0.12.0-alpha"
},
"spans": [
{
"attributes": [
{
"key": "http.request.method",
"value": {
"stringValue": "GET"
}
},
{
"key": "url.path",
"value": {
"stringValue": "/hello-gin"
}
}
],
"kind": 2,
"name": "GET",
"parentSpanId": "xxxxx",
"spanId": "xxxxx",
"status": {},
"traceId": "xxxxx"
}
]
},
{
"scope": {
"name": "go.opentelemetry.io/auto/net/http",
Expand Down
96 changes: 84 additions & 12 deletions internal/test/e2e/gin/verify.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,111 @@

load ../../test_helpers/utilities

SCOPE="go.opentelemetry.io/auto/github.com/gin-gonic/gin"
SCOPE="go.opentelemetry.io/auto/net/http"

@test "go-auto :: includes service.name in resource attributes" {
result=$(resource_attributes_received | jq "select(.key == \"service.name\").value.stringValue")
assert_equal "$result" '"sample-app"'
}

@test "${SCOPE} :: emits a span name '{http.request.method}' (per semconv)" {
result=$(span_names_for ${SCOPE})
@test "server :: emits a span name '{http.request.method}' (per semconv)" {
result=$(server_span_names_for ${SCOPE})
assert_equal "$result" '"GET"'
}

@test "${SCOPE} :: includes http.request.method attribute" {
result=$(span_attributes_for ${SCOPE} | jq "select(.key == \"http.request.method\").value.stringValue")
@test "client :: emits a span name '{http.request.method}' (per semconv)" {
result=$(client_span_names_for ${SCOPE})
assert_equal "$result" '"GET"'
}

@test "${SCOPE} :: includes url.path attribute" {
result=$(span_attributes_for ${SCOPE} | jq "select(.key == \"url.path\").value.stringValue")
@test "server :: includes http.request.method attribute" {
result=$(server_span_attributes_for ${SCOPE} | jq "select(.key == \"http.request.method\").value.stringValue")
assert_equal "$result" '"GET"'
}

@test "server :: includes url.path attribute" {
result=$(server_span_attributes_for ${SCOPE} | jq "select(.key == \"url.path\").value.stringValue")
assert_equal "$result" '"/hello-gin"'
}

@test "client :: includes url.path attribute" {
result=$(client_span_attributes_for ${SCOPE} | jq "select(.key == \"url.path\").value.stringValue")
assert_equal "$result" '"/hello-gin"'
}

@test "${SCOPE} :: trace ID present and valid in all spans" {
trace_id=$(spans_from_scope_named ${SCOPE} | jq ".traceId")
@test "server :: includes hhttp.response.status_code attribute" {
result=$(server_span_attributes_for ${SCOPE} | jq "select(.key == \"http.response.status_code\").value.intValue")
assert_equal "$result" '"200"'
}

@test "client :: includes http.response.status_code attribute" {
result=$(client_span_attributes_for ${SCOPE} | jq "select(.key == \"http.response.status_code\").value.intValue")
assert_equal "$result" '"200"'
}

@test "server :: trace ID present and valid in all spans" {
trace_id=$(server_spans_from_scope_named ${SCOPE} | jq ".traceId")
assert_regex "$trace_id" ${MATCH_A_TRACE_ID}
}

@test "${SCOPE} :: span ID present and valid in all spans" {
span_id=$(spans_from_scope_named ${SCOPE} | jq ".spanId")
@test "server :: span ID present and valid in all spans" {
span_id=$(server_spans_from_scope_named ${SCOPE} | jq ".spanId")
assert_regex "$span_id" ${MATCH_A_SPAN_ID}
}

@test "${SCOPE} :: expected (redacted) trace output" {
@test "server :: parent span ID present and valid in all spans" {
parent_span_id=$(server_spans_from_scope_named ${SCOPE} | jq ".parentSpanId")
assert_regex "$parent_span_id" ${MATCH_A_SPAN_ID}
}

@test "server :: network peer port is valid" {
net_peer_port=$(server_spans_from_scope_named ${SCOPE} | jq '.attributes[] | select (.key == "network.peer.port") | .value.intValue')
assert_regex "$net_peer_port" ${MATCH_A_PORT_NUMBER}
}

@test "client, server :: spans have same trace ID" {
client_trace_id=$(server_spans_from_scope_named ${SCOPE} | jq ".traceId")
server_trace_id=$(client_spans_from_scope_named ${SCOPE} | jq ".traceId")
assert_equal "$server_trace_id" "$client_trace_id"
}

@test "client, server :: server span has client span as parent" {
server_parent_span_id=$(server_spans_from_scope_named ${SCOPE} | jq ".parentSpanId")
client_span_id=$(client_spans_from_scope_named ${SCOPE} | jq ".spanId")
assert_equal "$client_span_id" "$server_parent_span_id"
}

@test "server :: includes server.address attribute" {
result=$(server_span_attributes_for ${SCOPE} | jq "select(.key == \"server.address\").value.stringValue")
assert_equal "$result" '"localhost"'
}

@test "server :: includes network.protocol.version attribute" {
result=$(server_span_attributes_for ${SCOPE} | jq "select(.key == \"network.protocol.version\").value.stringValue")
assert_equal "$result" '"1.1"'
}

@test "server :: includes network.peer.address attribute" {
result=$(server_span_attributes_for ${SCOPE} | jq "select(.key == \"network.peer.address\").value.stringValue")
assert_equal "$result" '"::1"'
}

@test "client :: includes server.address attribute" {
result=$(client_span_attributes_for ${SCOPE} | jq "select(.key == \"server.address\").value.stringValue")
assert_equal "$result" '"localhost"'
}

@test "client :: includes server.port attribute" {
result=$(client_span_attributes_for ${SCOPE} | jq "select(.key == \"server.port\").value.intValue")
assert_equal "$result" '"8080"'
}

@test "client :: includes network.protocol.version attribute" {
result=$(client_span_attributes_for ${SCOPE} | jq "select(.key == \"network.protocol.version\").value.stringValue")
assert_equal "$result" '"1.1"'
}

@test "client, server :: expected (redacted) trace output" {
redact_json
assert_equal "$(git --no-pager diff ${BATS_TEST_DIRNAME}/traces.json)" ""
}

0 comments on commit 70b4747

Please sign in to comment.