Skip to content

Commit 22c64cc

Browse files
committed
moar wip
1 parent 441b084 commit 22c64cc

File tree

15 files changed

+1196
-742
lines changed

15 files changed

+1196
-742
lines changed

packages/migrations/src/clickhouse-actions/015-otel-trace.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const action: Action = async exec => {
44
// Base tables as created by otel-exporter clickhouse
55
await exec(`
66
CREATE TABLE IF NOT EXISTS "otel_traces" (
7-
"Timestamp" DateTime64(9) CODEC(Delta(8), ZSTD(1))
7+
"Timestamp" DateTime64(9, 'UTC') CODEC(Delta(8), ZSTD(1))
88
, "TraceId" String CODEC(ZSTD(1))
99
, "SpanId" String CODEC(ZSTD(1))
1010
, "ParentSpanId" String CODEC(ZSTD(1))
@@ -19,7 +19,7 @@ export const action: Action = async exec => {
1919
, "Duration" UInt64 CODEC(ZSTD(1))
2020
, "StatusCode" LowCardinality(String) CODEC(ZSTD(1))
2121
, "StatusMessage" String CODEC(ZSTD(1))
22-
, "Events.Timestamp" Array(DateTime64(9)) CODEC(ZSTD(1))
22+
, "Events.Timestamp" Array(DateTime64(9, 'UTC')) CODEC(ZSTD(1))
2323
, "Events.Name" Array(LowCardinality(String)) CODEC(ZSTD(1))
2424
, "Events.Attributes" Array(Map(LowCardinality(String), String)) CODEC(ZSTD(1))
2525
, "Links.TraceId" Array(String) CODEC(ZSTD(1))
@@ -172,7 +172,7 @@ export const action: Action = async exec => {
172172
FROM
173173
"otel_traces"
174174
WHERE
175-
empty("ParentSpanId")
175+
empty("ParentSpanId") AND NOT empty("SpanAttributes"['hive.graphql.operation.type'])
176176
)
177177
`);
178178

packages/services/api/src/modules/operations/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createModule } from 'graphql-modules';
22
import { ClickHouse } from './providers/clickhouse-client';
33
import { OperationsManager } from './providers/operations-manager';
44
import { OperationsReader } from './providers/operations-reader';
5+
import { Traces } from './providers/traces';
56
import { resolvers } from './resolvers.generated';
67
import typeDefs from './module.graphql';
78

@@ -10,5 +11,5 @@ export const operationsModule = createModule({
1011
dirname: __dirname,
1112
typeDefs,
1213
resolvers,
13-
providers: [OperationsManager, OperationsReader, ClickHouse],
14+
providers: [OperationsManager, OperationsReader, ClickHouse, Traces],
1415
});

packages/services/api/src/modules/operations/module.graphql.mappers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type Dataloader from 'dataloader';
22
import type { ClientStatsValues, OperationStatsValues, PageInfo } from '../../__generated__/types';
33
import type { DateRange } from '../../shared/entities';
4+
import { Span, Trace } from './providers/traces';
45

56
// import { SqlValue } from './providers/sql';
67

@@ -58,3 +59,6 @@ export type TracesFilterOptionsMapper = {
5859
string
5960
>;
6061
};
62+
63+
export type TraceMapper = Trace;
64+
export type SpanMapper = Span;

packages/services/api/src/modules/operations/module.graphql.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export default gql`
272272
type Trace {
273273
id: ID!
274274
timestamp: DateTime!
275-
operationName: String!
275+
operationName: String
276276
operationType: GraphQLOperationType!
277277
duration: Int!
278278
subgraphs: [String!]!
@@ -284,6 +284,20 @@ export default gql`
284284
httpHost: String
285285
httpRoute: String
286286
httpUrl: String
287+
288+
spans: [Span!]!
289+
}
290+
291+
type Span {
292+
id: ID!
293+
traceId: ID!
294+
parentId: ID
295+
name: String!
296+
startTime: DateTime64!
297+
duration: SafeInt!
298+
endTime: DateTime64!
299+
resourceAttributes: JSONObject!
300+
spanAttributes: JSONObject!
287301
}
288302
289303
input TracesFilterInput {
@@ -335,6 +349,7 @@ export default gql`
335349
operation(hash: ID! @tag(name: "public")): Operation @tag(name: "public")
336350
traces(first: Int, after: String, filter: TracesFilterInput): TraceConnection!
337351
tracesFilterOptions(filter: TracesFilterInput): TracesFilterOptions!
352+
trace(traceId: ID!): Trace
338353
}
339354
340355
extend type Project {

packages/services/api/src/modules/operations/providers/clickhouse-client.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,23 @@ export class ClickHouse {
120120
},
121121
retry: {
122122
calculateDelay: info => {
123+
if (
124+
info.error.response?.body &&
125+
typeof info.error.response.body === 'object' &&
126+
'exception' in info.error.response.body &&
127+
typeof info.error.response.body.exception === 'string'
128+
) {
129+
this.logger.error(info.error.response.body.exception);
130+
// In case of development errors we don't need to retry
131+
// https://github.com/ClickHouse/ClickHouse/blob/eb33caaa13355761e4ceaba4a41b8801161ce327/src/Common/ErrorCodes.cpp#L55
132+
// //https://github.com/ClickHouse/ClickHouse/blob/eb33caaa13355761e4ceaba4a41b8801161ce327/src/Common/ErrorCodes.cpp#L68C7-L68C9
133+
if (
134+
info.error.response.body.exception.startsWith('Code: 47') ||
135+
info.error.response.body.exception.startsWith('Code: 62')
136+
) {
137+
return 0;
138+
}
139+
}
123140
span.setAttribute('retry.count', info.attemptCount);
124141

125142
if (info.attemptCount >= 6) {

0 commit comments

Comments
 (0)