Skip to content

Commit 5f7faa5

Browse files
committed
moar wip
1 parent f59772f commit 5f7faa5

File tree

3 files changed

+312
-170
lines changed

3 files changed

+312
-170
lines changed

configs/gateway.config.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* -e HIVE_ORGANIZATION_ACCESS_TOKEN="<organization_access_key>"
88
* -e HIVE_TARGET_REF="<target_ref>"
99
* -e DEBUG=1
10-
* ghcr.io/graphql-hive/gateway supergraph \
10+
* ghcr.io/graphql-hive/gateway:1.14.3-alpha-cf354599f0bca73b6f8b010a6747e42a17ef20d7 supergraph \
1111
* "http://host.docker.internal:3001/artifacts/v1/<target_id>" \
1212
* --hive-cdn-key '<cdn_key>'
1313
* ````
@@ -27,6 +27,12 @@ const useOnFetchTracer = (): GatewayPlugin => {
2727
onFetch({ url, options }) {
2828
upstreamCallHeaders.push({ url, headers: options.headers });
2929
},
30+
// onSubgraphExecute({ executionRequest, requestId, subgraphName, ...res }) {
31+
// return async function onSubgraphExecuteDone({ result }) {
32+
// const span = trace.getSpan(executionRequest.context.opentelemetry.activeContext());
33+
// console.log('DUDUDUDUDUDUDUD', span);
34+
// };
35+
// },
3036
onRequest({ request, url, endResponse, fetchAPI }) {
3137
if (url.pathname === '/upstream-fetch' && request.method === 'GET') {
3238
endResponse(fetchAPI.Response.json(upstreamCallHeaders));
@@ -71,6 +77,8 @@ class HiveTracingSpanProcessor implements SpanProcessor {
7177
const traceId = spanContext.traceId;
7278
const spanId = spanContext.spanId;
7379

80+
console.log(traceId, spanId);
81+
7482
// Initialize trace data structures if needed
7583
if (!this.activeSpans.has(traceId)) {
7684
this.activeSpans.set(traceId, new Map());
@@ -82,7 +90,8 @@ class HiveTracingSpanProcessor implements SpanProcessor {
8290
this.activeSpans.get(traceId)!.set(spanId, span);
8391

8492
// If this is a root span (no parent), mark it as the root span for this trace
85-
if (!span.parentSpanId) {
93+
// if (!span.parentSpanId) {
94+
if (!span.parentSpanContext?.spanId) {
8695
this.rootSpanIds.set(traceId, spanId);
8796
}
8897

@@ -128,9 +137,7 @@ class HiveTracingSpanProcessor implements SpanProcessor {
128137
rootSpan.setAttribute('hive.graphql.operation.type', operationType);
129138
rootSpan.setAttribute('hive.graphql.operation.name', operationName ?? '');
130139
rootSpan.setAttribute('hive.graphql.operation.document', document);
131-
132-
if (errorCount !== undefined)
133-
rootSpan.setAttribute('hive.graphql.error.count', errorCount);
140+
rootSpan.setAttribute('hive.graphql.error.count', String(errorCount ?? 0));
134141

135142
// Add the subgraph names as a comma-separated list
136143
if (subgraphNamesForTrace && subgraphNamesForTrace.size > 0) {
@@ -147,6 +154,7 @@ class HiveTracingSpanProcessor implements SpanProcessor {
147154
// For any subgraph span that's ending, make sure we capture its name
148155
if (span.name && span.name.startsWith('subgraph.execute')) {
149156
const subgraphName = span.attributes['gateway.upstream.subgraph.name'];
157+
150158
if (subgraphName && typeof subgraphName === 'string' && subgraphNamesForTrace) {
151159
subgraphNamesForTrace.add(subgraphName);
152160

@@ -161,6 +169,20 @@ class HiveTracingSpanProcessor implements SpanProcessor {
161169
}
162170
}
163171
}
172+
173+
// add hive branded attributes
174+
//
175+
span.attributes['hive.graphql.subgraph.name'] =
176+
span.attributes['gateway.upstream.subgraph.name'];
177+
span.attributes['hive.graphql.operation.document'] = span.attributes['graphql.document'];
178+
span.attributes['hive.graphql.operation.name'] = span.attributes['graphql.operation.name'];
179+
span.attributes['hive.graphql.operation.type'] = span.attributes['graphql.operation.type'];
180+
// TODO: attributes for error codes
181+
// hive.graphql.error.count
182+
span.attributes['hive.graphql.error.count'] = '0';
183+
// hive.graphql.error.codes
184+
// span.setAttribute('hive.graphql.error.codes', '');
185+
//
164186
}
165187

166188
// Clean up the span reference
@@ -195,6 +217,7 @@ async function createHiveTracingSpanProcessor(): Promise<HiveTracingSpanProcesso
195217

196218
export const gatewayConfig = defineConfig({
197219
openTelemetry: {
220+
contextManager: false,
198221
exporters: [
199222
createHiveTracingSpanProcessor(),
200223
createOtlpHttpExporter(

docker/configs/otel-collector/config.yaml

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,29 @@ processors:
2626
- key: hive.target_id
2727
from_context: auth.targetId
2828
action: insert
29-
filter/drop_missing_attributes:
30-
error_mode: ignore
31-
traces:
32-
span:
33-
# prettier-ignore
34-
- not (
35-
attributes["http.status"] != nil and
36-
attributes["http.host"] != nil and
37-
attributes["http.method"] != nil and
38-
attributes["http.route"] != nil and
39-
attributes["http.url"] != nil and
40-
(
41-
attributes["hive.graphql.operation.type"] == "query" or
42-
attributes["hive.graphql.operation.type"] == "mutation" or
43-
attributes["hive.graphql.operation.type"] == "subscription"
44-
)
45-
)
29+
# filter/drop_missing_attributes:
30+
# error_mode: ignore
31+
# traces:
32+
# span:
33+
# # prettier-ignore
34+
# - not (
35+
# attributes["http.status"] != nil and
36+
# attributes["http.host"] != nil and
37+
# attributes["http.method"] != nil and
38+
# attributes["http.route"] != nil and
39+
# attributes["http.url"] != nil and
40+
# attributes["hive.graphql.operation.document"] != nil and
41+
# (
42+
# attributes["hive.graphql.operation.type"] == "query" or
43+
# attributes["hive.graphql.operation.type"] == "mutation" or
44+
# attributes["hive.graphql.operation.type"] == "subscription"
45+
# )
46+
# )
4647
exporters:
47-
# debug:
48-
# verbosity: detailed
49-
# sampling_initial: 5
50-
# sampling_thereafter: 200
48+
debug:
49+
verbosity: detailed
50+
sampling_initial: 5
51+
sampling_thereafter: 200
5152
clickhouse:
5253
endpoint: tcp://clickhouse:9000?dial_timeout=10s&compress=lz4
5354
database: default
@@ -83,4 +84,4 @@ service:
8384
# filter/drop_missing_attributes,
8485
batch,
8586
]
86-
exporters: [clickhouse]
87+
exporters: [clickhouse, debug]

0 commit comments

Comments
 (0)