-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TT-7902] Detailed Tracing #5294
Changes from 24 commits
1d86a23
10c54c7
45f08e1
cc5fb1d
6027a77
0b50bb7
b828b57
f1df8e1
eaa1139
6bd64b7
f0d6d7c
8bd46b4
b24ad00
ae25d2a
81d8702
de7556f
bb582fc
5ffd2c6
1ee9a1f
3ff2a8b
a175801
3120cdc
84ef4de
c3284a5
6b84656
8c83546
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,7 @@ tasks: | |
sources: | ||
- go.mod | ||
- go.sum | ||
- './**/*.go' | ||
|
||
- "./**/*.go" | ||
|
||
test:plugin-compiler: | ||
desc: "Plugin compiler local build/test" | ||
|
@@ -51,7 +50,6 @@ tasks: | |
- docker compose -f ci/tests/tracing/docker-compose.yml up -d | ||
- tracetest configure -g --endpoint http://localhost:11633 | ||
|
||
|
||
test:opentelemetry:test: | ||
desc: "run e2e opentelemetry tests" | ||
deps: | ||
|
@@ -63,16 +61,21 @@ tasks: | |
- tracetest test run -d ./ci/tests/tracing/scenarios/tyk_tykprotocol_200.yml -w -o pretty | ||
- tracetest test run -d ./ci/tests/tracing/scenarios/tyk_tykprotocol-auth_401.yml -w -o pretty | ||
- tracetest test run -d ./ci/tests/tracing/scenarios/tyk_grpcapi_200.yml -w -o pretty | ||
|
||
- tracetest test run -d ./ci/tests/tracing/scenarios/tyk_versioned_200.yml -w -o pretty | ||
- tracetest test run -d ./ci/tests/tracing/scenarios/tyk_versioned_403.yml -w -o pretty | ||
- tracetest test run -d ./ci/tests/tracing/scenarios/tyk_versioned_not_detailed_200.yml -w -o pretty | ||
- tracetest test run -d ./ci/tests/tracing/scenarios/tyk_versioned_not_detailed_403.yml -w -o pretty | ||
|
||
test:opentelemetry:teardown: | ||
desc: "teardown e2e opentelemetry tests enviroment" | ||
cmds: | ||
- docker compose -f ci/tests/tracing/docker-compose.yml down --remove-orphans | ||
|
||
test:opentelemetry: | ||
desc : "setup, execute and shutdown e2e opentelemetry tests" | ||
desc: "setup, execute and shutdown e2e opentelemetry tests" | ||
cmds: | ||
- task: test:opentelemetry:setup | ||
- task: test:opentelemetry:test | ||
- task: test:opentelemetry:teardown | ||
- | | ||
set -e | ||
task test:opentelemetry:setup | ||
trap 'task test:opentelemetry:teardown' EXIT | ||
Comment on lines
+77
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm ensuring teardown is executed no matter if the test failed or not |
||
task test:opentelemetry:test |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -724,7 +724,10 @@ const Schema = `{ | |
}, | ||
"is_oas": { | ||
"type": "boolean" | ||
} | ||
}, | ||
"detailed_tracing": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this linted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is! |
||
"type": "boolean" | ||
} | ||
}, | ||
"required": [ | ||
"name", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
{ | ||
"name": "VersionedNotDetailedAPI", | ||
"api_id": "7", | ||
"org_id": "default", | ||
"definition": { | ||
"enabled": false, | ||
"name": "", | ||
"default": "", | ||
"location": "url-param", | ||
"key": "version", | ||
"strip_path": false, | ||
"strip_versioning_data": false, | ||
"versions": {} | ||
}, | ||
"use_keyless": true, | ||
"auth": { | ||
"auth_header_name": "" | ||
}, | ||
"version_data": { | ||
"not_versioned": false, | ||
"default_version": "v1", | ||
"versions": { | ||
"v1": { | ||
"name": "v1", | ||
"expires": "2080-07-28 15:00", | ||
"paths": { | ||
"ignored": [], | ||
"white_list": [], | ||
"black_list": [] | ||
}, | ||
"use_extended_paths": true, | ||
"extended_paths": { | ||
"ignored": [], | ||
"white_list": [], | ||
"black_list": [], | ||
"transform": [], | ||
"transform_response": [], | ||
"transform_jq": [], | ||
"transform_jq_response": [], | ||
"transform_headers": [], | ||
"transform_response_headers": [], | ||
"hard_timeouts": [], | ||
"circuit_breakers": [], | ||
"url_rewrites": [], | ||
"virtual": [], | ||
"size_limits": [], | ||
"method_transforms": [], | ||
"track_endpoints": [], | ||
"do_not_track_endpoints": [], | ||
"validate_json": [], | ||
"internal": [], | ||
"persist_graphql": [] | ||
}, | ||
"global_headers": {}, | ||
"global_headers_remove": [], | ||
"global_response_headers": {}, | ||
"global_response_headers_remove": [], | ||
"ignore_endpoint_case": false, | ||
"global_size_limit": 0, | ||
"override_target": "https://httpbin.org" | ||
}, | ||
"v2": { | ||
"name": "v2", | ||
"expires": "2080-07-29 15:00", | ||
"paths": { | ||
"ignored": [], | ||
"white_list": [], | ||
"black_list": [] | ||
}, | ||
"use_extended_paths": true, | ||
"extended_paths": { | ||
"ignored": [], | ||
"white_list": [], | ||
"black_list": [], | ||
"transform": [], | ||
"transform_response": [], | ||
"transform_jq": [], | ||
"transform_jq_response": [], | ||
"transform_headers": [], | ||
"transform_response_headers": [], | ||
"hard_timeouts": [], | ||
"circuit_breakers": [], | ||
"url_rewrites": [], | ||
"virtual": [], | ||
"size_limits": [], | ||
"method_transforms": [], | ||
"track_endpoints": [], | ||
"do_not_track_endpoints": [], | ||
"validate_json": [], | ||
"internal": [], | ||
"persist_graphql": [] | ||
}, | ||
"global_headers": {}, | ||
"global_headers_remove": [], | ||
"global_response_headers": {}, | ||
"global_response_headers_remove": [], | ||
"ignore_endpoint_case": false, | ||
"global_size_limit": 0, | ||
"override_target": "https://httpbin.org" | ||
} | ||
} | ||
}, | ||
"proxy": { | ||
"listen_path": "/versioned-not-detailed/", | ||
"target_url": "http://httpbin:80/", | ||
"strip_listen_path": true | ||
}, | ||
"do_not_track": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
type: Test | ||
spec: | ||
id: qS_lLV3Vg | ||
name: Versioned not detailed API | ||
trigger: | ||
type: http | ||
httpRequest: | ||
method: GET | ||
url: tyk:8080/versioned-not-detailed/ip?version=v1 | ||
headers: | ||
- key: Content-Type | ||
value: application/json | ||
specs: | ||
- selector: span[tracetest.span.type="http" name="GET /versioned-not-detailed/ip" http.method="GET"] | ||
name: Checking API attributes + version | ||
assertions: | ||
- attr:tyk.api.id = 7 | ||
- attr:tyk.api.name = "VersionedNotDetailedAPI" | ||
- attr:tyk.api.orgid = "default" | ||
- attr:tyk.api.path = "/versioned-not-detailed/" | ||
- attr:tyk.api.version = "v1" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
type: Test | ||
spec: | ||
id: p1BLP4q4g | ||
name: Versioned not detailed error | ||
trigger: | ||
type: http | ||
httpRequest: | ||
method: GET | ||
url: tyk:8080/versioned-not-detailed/ip?version=v3 | ||
headers: | ||
- key: Content-Type | ||
value: application/json | ||
specs: | ||
- selector: span[tracetest.span.type="http" name="GET /versioned-not-detailed/ip" http.method="GET"] | ||
name: Checking attributes + wrong version in attributes | ||
assertions: | ||
- attr:tyk.api.version = "v3" | ||
- attr:http.status_code = 403 | ||
- attr:tyk.api.id = 7 | ||
- attr:tyk.api.name = "VersionedNotDetailedAPI" | ||
- attr:tyk.api.orgid = "default" | ||
- attr:tyk.api.path = "/versioned-not-detailed/" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package gateway | |
|
||
import ( | ||
"bytes" | ||
"context" | ||
"crypto/md5" | ||
"errors" | ||
"fmt" | ||
|
@@ -29,6 +30,8 @@ import ( | |
"github.com/TykTechnologies/tyk/storage" | ||
"github.com/TykTechnologies/tyk/trace" | ||
"github.com/TykTechnologies/tyk/user" | ||
|
||
tyktrace "github.com/TykTechnologies/opentelemetry/trace" | ||
) | ||
|
||
const ( | ||
|
@@ -66,17 +69,21 @@ func (tr TraceMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Request, | |
setContext(r, ctx) | ||
return tr.TykMiddleware.ProcessRequest(w, r, conf) | ||
} else if baseMw := tr.Base(); baseMw != nil { | ||
if cfg := baseMw.Gw.GetConfig(); cfg.OpenTelemetry.Enabled { | ||
ctx, span := baseMw.Gw.TracerProvider.Tracer().Start(r.Context(), tr.Name()) | ||
defer span.End() | ||
|
||
setContext(r, ctx) | ||
cfg := baseMw.Gw.GetConfig() | ||
if cfg.OpenTelemetry.Enabled { | ||
var span tyktrace.Span | ||
if baseMw.Spec.DetailedTracing { | ||
var ctx context.Context | ||
ctx, span = baseMw.Gw.TracerProvider.Tracer().Start(r.Context(), tr.Name()) | ||
defer span.End() | ||
setContext(r, ctx) | ||
} else { | ||
span = tyktrace.SpanFromContext(r.Context()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this function to otel internal pkg, so we don't have to import /opentelemetry/trace here |
||
} | ||
|
||
err, i := tr.TykMiddleware.ProcessRequest(w, r, conf) | ||
if err != nil { | ||
span.SetStatus(otel.SPAN_STATUS_ERROR, err.Error()) | ||
} else { | ||
span.SetStatus(otel.SPAN_STATUS_OK, "") | ||
} | ||
|
||
attrs := ctxGetSpanAttributes(r, tr.TykMiddleware.Name()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change made by the linter