@perses-dev/tempo-plugin 0.47.0 → 0.48.0-rc0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/TraceQLEditor.js +98 -0
- package/dist/cjs/components/TraceQLExtension.js +73 -0
- package/dist/cjs/components/complete.js +322 -0
- package/dist/cjs/components/highlight.js +41 -0
- package/dist/cjs/components/index.js +30 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/model/tempo-client.js +28 -13
- package/dist/cjs/plugins/tempo-datasource.js +22 -4
- package/dist/cjs/plugins/tempo-trace-query/DashboardTempoTraceQueryEditor.js +6 -2
- package/dist/cjs/plugins/tempo-trace-query/get-trace-data.js +3 -13
- package/dist/components/TraceQLEditor.d.ts +7 -0
- package/dist/components/TraceQLEditor.d.ts.map +1 -0
- package/dist/{plugins/tempo-trace-query → components}/TraceQLEditor.js +20 -4
- package/dist/components/TraceQLEditor.js.map +1 -0
- package/dist/components/TraceQLExtension.d.ts +8 -0
- package/dist/components/TraceQLExtension.d.ts.map +1 -0
- package/dist/components/TraceQLExtension.js +65 -0
- package/dist/components/TraceQLExtension.js.map +1 -0
- package/dist/components/complete.d.ts +36 -0
- package/dist/components/complete.d.ts.map +1 -0
- package/dist/components/complete.js +313 -0
- package/dist/components/complete.js.map +1 -0
- package/dist/components/highlight.d.ts +2 -0
- package/dist/components/highlight.d.ts.map +1 -0
- package/dist/components/highlight.js +33 -0
- package/dist/components/highlight.js.map +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +15 -0
- package/dist/components/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/model/api-types.d.ts +60 -9
- package/dist/model/api-types.d.ts.map +1 -1
- package/dist/model/api-types.js.map +1 -1
- package/dist/model/tempo-client.d.ts +18 -8
- package/dist/model/tempo-client.d.ts.map +1 -1
- package/dist/model/tempo-client.js +21 -8
- package/dist/model/tempo-client.js.map +1 -1
- package/dist/plugins/tempo-datasource.d.ts.map +1 -1
- package/dist/plugins/tempo-datasource.js +23 -5
- package/dist/plugins/tempo-datasource.js.map +1 -1
- package/dist/plugins/tempo-trace-query/DashboardTempoTraceQueryEditor.d.ts.map +1 -1
- package/dist/plugins/tempo-trace-query/DashboardTempoTraceQueryEditor.js +6 -2
- package/dist/plugins/tempo-trace-query/DashboardTempoTraceQueryEditor.js.map +1 -1
- package/dist/plugins/tempo-trace-query/get-trace-data.d.ts.map +1 -1
- package/dist/plugins/tempo-trace-query/get-trace-data.js +3 -13
- package/dist/plugins/tempo-trace-query/get-trace-data.js.map +1 -1
- package/dist/test/mock-data.d.ts +5 -5
- package/dist/test/mock-data.d.ts.map +1 -1
- package/dist/test/mock-data.js.map +1 -1
- package/package.json +8 -4
- package/dist/cjs/plugins/tempo-trace-query/TraceQLEditor.js +0 -46
- package/dist/plugins/tempo-trace-query/TraceQLEditor.d.ts +0 -4
- package/dist/plugins/tempo-trace-query/TraceQLEditor.d.ts.map +0 -1
- package/dist/plugins/tempo-trace-query/TraceQLEditor.js.map +0 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "TraceQLEditor", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return TraceQLEditor;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _jsxruntime = require("react/jsx-runtime");
|
|
24
|
+
const _react = require("react");
|
|
25
|
+
const _material = require("@mui/material");
|
|
26
|
+
const _reactcodemirror = /*#__PURE__*/ _interop_require_wildcard(require("@uiw/react-codemirror"));
|
|
27
|
+
const _core = require("@perses-dev/core");
|
|
28
|
+
const _TraceQLExtension = require("./TraceQLExtension");
|
|
29
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
30
|
+
if (typeof WeakMap !== "function") return null;
|
|
31
|
+
var cacheBabelInterop = new WeakMap();
|
|
32
|
+
var cacheNodeInterop = new WeakMap();
|
|
33
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
34
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
35
|
+
})(nodeInterop);
|
|
36
|
+
}
|
|
37
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
38
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
42
|
+
return {
|
|
43
|
+
default: obj
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
47
|
+
if (cache && cache.has(obj)) {
|
|
48
|
+
return cache.get(obj);
|
|
49
|
+
}
|
|
50
|
+
var newObj = {
|
|
51
|
+
__proto__: null
|
|
52
|
+
};
|
|
53
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
54
|
+
for(var key in obj){
|
|
55
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
56
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
57
|
+
if (desc && (desc.get || desc.set)) {
|
|
58
|
+
Object.defineProperty(newObj, key, desc);
|
|
59
|
+
} else {
|
|
60
|
+
newObj[key] = obj[key];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
newObj.default = obj;
|
|
65
|
+
if (cache) {
|
|
66
|
+
cache.set(obj, newObj);
|
|
67
|
+
}
|
|
68
|
+
return newObj;
|
|
69
|
+
}
|
|
70
|
+
function TraceQLEditor({ completeConfig, ...rest }) {
|
|
71
|
+
const theme = (0, _material.useTheme)();
|
|
72
|
+
const isDarkMode = theme.palette.mode === 'dark';
|
|
73
|
+
const traceQLExtension = (0, _react.useMemo)(()=>{
|
|
74
|
+
return (0, _TraceQLExtension.TraceQLExtension)(completeConfig);
|
|
75
|
+
}, [
|
|
76
|
+
completeConfig
|
|
77
|
+
]);
|
|
78
|
+
var _rest_value;
|
|
79
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_reactcodemirror.default, {
|
|
80
|
+
...rest,
|
|
81
|
+
style: {
|
|
82
|
+
border: `1px solid ${theme.palette.divider}`
|
|
83
|
+
},
|
|
84
|
+
theme: isDarkMode ? 'dark' : 'light',
|
|
85
|
+
basicSetup: {
|
|
86
|
+
highlightActiveLine: false,
|
|
87
|
+
highlightActiveLineGutter: false,
|
|
88
|
+
foldGutter: false,
|
|
89
|
+
// The explore view accepts either a TraceQL query or a Trace ID as input. The lezer grammar marks Trace IDs as invalid,
|
|
90
|
+
// therefore let's disable syntax highlighting if the input is a Trace ID.
|
|
91
|
+
syntaxHighlighting: !(0, _core.isValidTraceId)((_rest_value = rest.value) !== null && _rest_value !== void 0 ? _rest_value : '')
|
|
92
|
+
},
|
|
93
|
+
extensions: [
|
|
94
|
+
_reactcodemirror.EditorView.lineWrapping,
|
|
95
|
+
traceQLExtension
|
|
96
|
+
]
|
|
97
|
+
});
|
|
98
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "TraceQLExtension", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return TraceQLExtension;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _language = require("@codemirror/language");
|
|
24
|
+
const _lezertraceql = require("@grafana/lezer-traceql");
|
|
25
|
+
const _tempodatasource = require("../plugins/tempo-datasource");
|
|
26
|
+
const _highlight = require("./highlight");
|
|
27
|
+
const _complete = require("./complete");
|
|
28
|
+
function traceQLLanguage() {
|
|
29
|
+
return _language.LRLanguage.define({
|
|
30
|
+
parser: _lezertraceql.parser.configure({
|
|
31
|
+
props: [
|
|
32
|
+
_highlight.traceQLHighlight
|
|
33
|
+
]
|
|
34
|
+
}),
|
|
35
|
+
languageData: {
|
|
36
|
+
closeBrackets: {
|
|
37
|
+
brackets: [
|
|
38
|
+
'(',
|
|
39
|
+
'[',
|
|
40
|
+
'{',
|
|
41
|
+
"'",
|
|
42
|
+
'"',
|
|
43
|
+
'`'
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
commentTokens: {
|
|
47
|
+
line: '//'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function getTempoClient(completionCfg) {
|
|
53
|
+
if (completionCfg.client) {
|
|
54
|
+
return completionCfg.client;
|
|
55
|
+
}
|
|
56
|
+
if (completionCfg.endpoint) {
|
|
57
|
+
return _tempodatasource.TempoDatasource.createClient({
|
|
58
|
+
directUrl: completionCfg.endpoint
|
|
59
|
+
}, {});
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
function TraceQLExtension(completionCfg) {
|
|
64
|
+
const tempoClient = getTempoClient(completionCfg);
|
|
65
|
+
const language = traceQLLanguage();
|
|
66
|
+
const completion = language.data.of({
|
|
67
|
+
autocomplete: (ctx)=>(0, _complete.complete)(ctx, tempoClient).catch((e)=>console.error('error during TraceQL auto-complete', e))
|
|
68
|
+
});
|
|
69
|
+
return [
|
|
70
|
+
language,
|
|
71
|
+
completion
|
|
72
|
+
];
|
|
73
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
complete: function() {
|
|
25
|
+
return complete;
|
|
26
|
+
},
|
|
27
|
+
identifyCompletions: function() {
|
|
28
|
+
return identifyCompletions;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const _language = require("@codemirror/language");
|
|
32
|
+
const _lezertraceql = require("@grafana/lezer-traceql");
|
|
33
|
+
async function complete({ state, pos }, client) {
|
|
34
|
+
// First, identify the completion scopes, for example Scopes() and TagName(scope=intrinsic)
|
|
35
|
+
const completions = identifyCompletions(state, pos, (0, _language.syntaxTree)(state));
|
|
36
|
+
if (!completions) {
|
|
37
|
+
// No completion scopes found for current cursor position.
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
// Then, retrieve completion options for all identified scopes (from the Tempo API).
|
|
41
|
+
const options = await retrieveOptions(completions.scopes, client);
|
|
42
|
+
return {
|
|
43
|
+
options,
|
|
44
|
+
from: completions.from,
|
|
45
|
+
to: completions.to
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function identifyCompletions(state, pos, tree) {
|
|
49
|
+
const node = tree.resolveInner(pos, -1);
|
|
50
|
+
switch(node.type.id){
|
|
51
|
+
case _lezertraceql.SpansetFilter:
|
|
52
|
+
var _node_firstChild;
|
|
53
|
+
// autocomplete {
|
|
54
|
+
// autocomplete {}
|
|
55
|
+
// do not autocomplete if cursor is after } or { status=ok }
|
|
56
|
+
if ((node.firstChild === null || ((_node_firstChild = node.firstChild) === null || _node_firstChild === void 0 ? void 0 : _node_firstChild.type.id) === 0) && !state.sliceDoc(node.from, pos).includes('}')) {
|
|
57
|
+
return {
|
|
58
|
+
scopes: [
|
|
59
|
+
{
|
|
60
|
+
kind: 'Scopes'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
kind: 'TagName',
|
|
64
|
+
scope: 'intrinsic'
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
from: pos
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
case _lezertraceql.FieldExpression:
|
|
72
|
+
// autocomplete { status=ok &&
|
|
73
|
+
return {
|
|
74
|
+
scopes: [
|
|
75
|
+
{
|
|
76
|
+
kind: 'Scopes'
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
kind: 'TagName',
|
|
80
|
+
scope: 'intrinsic'
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
from: pos
|
|
84
|
+
};
|
|
85
|
+
case _lezertraceql.AttributeField:
|
|
86
|
+
var _node_firstChild1, _node_firstChild2;
|
|
87
|
+
// autocomplete { resource.
|
|
88
|
+
if (((_node_firstChild1 = node.firstChild) === null || _node_firstChild1 === void 0 ? void 0 : _node_firstChild1.type.id) === _lezertraceql.Resource) {
|
|
89
|
+
return {
|
|
90
|
+
scopes: [
|
|
91
|
+
{
|
|
92
|
+
kind: 'TagName',
|
|
93
|
+
scope: 'resource'
|
|
94
|
+
}
|
|
95
|
+
],
|
|
96
|
+
from: pos
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// autocomplete { span.
|
|
100
|
+
if (((_node_firstChild2 = node.firstChild) === null || _node_firstChild2 === void 0 ? void 0 : _node_firstChild2.type.id) === _lezertraceql.Span) {
|
|
101
|
+
return {
|
|
102
|
+
scopes: [
|
|
103
|
+
{
|
|
104
|
+
kind: 'TagName',
|
|
105
|
+
scope: 'span'
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
from: pos
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
// autocomplete { .
|
|
112
|
+
if (state.sliceDoc(node.from, node.to) === '.') {
|
|
113
|
+
return {
|
|
114
|
+
scopes: [
|
|
115
|
+
{
|
|
116
|
+
kind: 'TagName',
|
|
117
|
+
scope: 'resource'
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
kind: 'TagName',
|
|
121
|
+
scope: 'span'
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
from: pos
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
case _lezertraceql.Identifier:
|
|
129
|
+
var _node_parent;
|
|
130
|
+
if (((_node_parent = node.parent) === null || _node_parent === void 0 ? void 0 : _node_parent.type.id) === _lezertraceql.AttributeField) {
|
|
131
|
+
var _node_parent_firstChild, _node_parent1, _node_parent_firstChild1, _node_parent2, _node_parent_firstChild2, _node_parent3;
|
|
132
|
+
const text = state.sliceDoc(node.parent.from, node.parent.to);
|
|
133
|
+
// autocomplete { span:s
|
|
134
|
+
// only intrinsic fields can have a : in the name.
|
|
135
|
+
if (text.includes(':')) {
|
|
136
|
+
return {
|
|
137
|
+
scopes: [
|
|
138
|
+
{
|
|
139
|
+
kind: 'TagName',
|
|
140
|
+
scope: 'intrinsic'
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
from: node.parent.from
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
// autocomplete { resource.s
|
|
147
|
+
if (((_node_parent1 = node.parent) === null || _node_parent1 === void 0 ? void 0 : (_node_parent_firstChild = _node_parent1.firstChild) === null || _node_parent_firstChild === void 0 ? void 0 : _node_parent_firstChild.type.id) === _lezertraceql.Resource) {
|
|
148
|
+
return {
|
|
149
|
+
scopes: [
|
|
150
|
+
{
|
|
151
|
+
kind: 'TagName',
|
|
152
|
+
scope: 'resource'
|
|
153
|
+
}
|
|
154
|
+
],
|
|
155
|
+
from: node.from
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// autocomplete { span.s
|
|
159
|
+
if (((_node_parent2 = node.parent) === null || _node_parent2 === void 0 ? void 0 : (_node_parent_firstChild1 = _node_parent2.firstChild) === null || _node_parent_firstChild1 === void 0 ? void 0 : _node_parent_firstChild1.type.id) === _lezertraceql.Span) {
|
|
160
|
+
return {
|
|
161
|
+
scopes: [
|
|
162
|
+
{
|
|
163
|
+
kind: 'TagName',
|
|
164
|
+
scope: 'span'
|
|
165
|
+
}
|
|
166
|
+
],
|
|
167
|
+
from: node.from
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
// autocomplete { .s
|
|
171
|
+
if (((_node_parent3 = node.parent) === null || _node_parent3 === void 0 ? void 0 : (_node_parent_firstChild2 = _node_parent3.firstChild) === null || _node_parent_firstChild2 === void 0 ? void 0 : _node_parent_firstChild2.type.id) === _lezertraceql.Identifier) {
|
|
172
|
+
return {
|
|
173
|
+
scopes: [
|
|
174
|
+
{
|
|
175
|
+
kind: 'TagName',
|
|
176
|
+
scope: 'resource'
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
kind: 'TagName',
|
|
180
|
+
scope: 'span'
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
from: node.from
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
case _lezertraceql.FieldOp:
|
|
189
|
+
var _node_parent_firstChild3, _node_parent4;
|
|
190
|
+
// autocomplete { status=
|
|
191
|
+
// autocomplete { span.http.method=
|
|
192
|
+
if (((_node_parent4 = node.parent) === null || _node_parent4 === void 0 ? void 0 : (_node_parent_firstChild3 = _node_parent4.firstChild) === null || _node_parent_firstChild3 === void 0 ? void 0 : _node_parent_firstChild3.type.id) === _lezertraceql.FieldExpression) {
|
|
193
|
+
const fieldExpr = node.parent.firstChild;
|
|
194
|
+
const attribute = state.sliceDoc(fieldExpr.from, fieldExpr.to);
|
|
195
|
+
return {
|
|
196
|
+
scopes: [
|
|
197
|
+
{
|
|
198
|
+
kind: 'TagValue',
|
|
199
|
+
tag: attribute,
|
|
200
|
+
quotes: true
|
|
201
|
+
}
|
|
202
|
+
],
|
|
203
|
+
from: pos
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
case _lezertraceql.String:
|
|
208
|
+
var _node_parent_parent_parent_firstChild, _node_parent_parent_parent, _node_parent_parent, _node_parent5;
|
|
209
|
+
// autocomplete { resource.service.name="
|
|
210
|
+
if (((_node_parent5 = node.parent) === null || _node_parent5 === void 0 ? void 0 : (_node_parent_parent = _node_parent5.parent) === null || _node_parent_parent === void 0 ? void 0 : (_node_parent_parent_parent = _node_parent_parent.parent) === null || _node_parent_parent_parent === void 0 ? void 0 : (_node_parent_parent_parent_firstChild = _node_parent_parent_parent.firstChild) === null || _node_parent_parent_parent_firstChild === void 0 ? void 0 : _node_parent_parent_parent_firstChild.type.id) === _lezertraceql.FieldExpression) {
|
|
211
|
+
const fieldExpr = node.parent.parent.parent.firstChild;
|
|
212
|
+
const attribute = state.sliceDoc(fieldExpr.from, fieldExpr.to);
|
|
213
|
+
return {
|
|
214
|
+
scopes: [
|
|
215
|
+
{
|
|
216
|
+
kind: 'TagValue',
|
|
217
|
+
tag: attribute
|
|
218
|
+
}
|
|
219
|
+
],
|
|
220
|
+
from: node.from + 1
|
|
221
|
+
}; // node.from+1 to ignore leading "
|
|
222
|
+
}
|
|
223
|
+
break;
|
|
224
|
+
case 0 /* error node */ :
|
|
225
|
+
var _node_prevSibling, _node_parent_firstChild4, _node_parent6, _node_parent7, _node_parent8;
|
|
226
|
+
// autocomplete { status=e
|
|
227
|
+
if (((_node_prevSibling = node.prevSibling) === null || _node_prevSibling === void 0 ? void 0 : _node_prevSibling.type.id) === _lezertraceql.FieldOp && ((_node_parent6 = node.parent) === null || _node_parent6 === void 0 ? void 0 : (_node_parent_firstChild4 = _node_parent6.firstChild) === null || _node_parent_firstChild4 === void 0 ? void 0 : _node_parent_firstChild4.type.id) === _lezertraceql.FieldExpression) {
|
|
228
|
+
const fieldExpr = node.parent.firstChild;
|
|
229
|
+
const attribute = state.sliceDoc(fieldExpr.from, fieldExpr.to);
|
|
230
|
+
return {
|
|
231
|
+
scopes: [
|
|
232
|
+
{
|
|
233
|
+
kind: 'TagValue',
|
|
234
|
+
tag: attribute
|
|
235
|
+
}
|
|
236
|
+
],
|
|
237
|
+
from: node.from
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
// autocomplete { s
|
|
241
|
+
// autocomplete { status=ok && s
|
|
242
|
+
if (((_node_parent7 = node.parent) === null || _node_parent7 === void 0 ? void 0 : _node_parent7.type.id) === _lezertraceql.SpansetFilter || ((_node_parent8 = node.parent) === null || _node_parent8 === void 0 ? void 0 : _node_parent8.type.id) === _lezertraceql.FieldExpression) {
|
|
243
|
+
return {
|
|
244
|
+
scopes: [
|
|
245
|
+
{
|
|
246
|
+
kind: 'Scopes'
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
kind: 'TagName',
|
|
250
|
+
scope: 'intrinsic'
|
|
251
|
+
}
|
|
252
|
+
],
|
|
253
|
+
from: node.from
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Retrieve all completion options based on the previously identified completion scopes.
|
|
261
|
+
*/ async function retrieveOptions(completions, client) {
|
|
262
|
+
const results = [];
|
|
263
|
+
for (const completion of completions){
|
|
264
|
+
switch(completion.kind){
|
|
265
|
+
case 'Scopes':
|
|
266
|
+
results.push(Promise.resolve([
|
|
267
|
+
{
|
|
268
|
+
label: 'span'
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
label: 'resource'
|
|
272
|
+
}
|
|
273
|
+
]));
|
|
274
|
+
break;
|
|
275
|
+
case 'TagName':
|
|
276
|
+
if (client) {
|
|
277
|
+
results.push(completeTagName(client, completion.scope));
|
|
278
|
+
}
|
|
279
|
+
break;
|
|
280
|
+
case 'TagValue':
|
|
281
|
+
if (client) {
|
|
282
|
+
results.push(completeTagValue(client, completion.tag, completion.quotes));
|
|
283
|
+
}
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
// Retrieve options concurrently
|
|
288
|
+
// e.g. for unscoped attribute fields, retrieve list of span and resource attributes concurrently.
|
|
289
|
+
const options = await Promise.all(results);
|
|
290
|
+
return options.flat();
|
|
291
|
+
}
|
|
292
|
+
async function completeTagName(client, scope) {
|
|
293
|
+
const response = await client.searchTags({
|
|
294
|
+
scope
|
|
295
|
+
});
|
|
296
|
+
return response.scopes.flatMap((scope)=>scope.tags).map((tag)=>({
|
|
297
|
+
label: tag
|
|
298
|
+
}));
|
|
299
|
+
}
|
|
300
|
+
async function completeTagValue(client, tag, quotes) {
|
|
301
|
+
const response = await client.searchTagValues({
|
|
302
|
+
tag
|
|
303
|
+
});
|
|
304
|
+
const completions = [];
|
|
305
|
+
for (const { type, value } of response.tagValues){
|
|
306
|
+
switch(type){
|
|
307
|
+
case 'string':
|
|
308
|
+
completions.push({
|
|
309
|
+
displayLabel: value,
|
|
310
|
+
label: quotes ? `"${value}"` : value
|
|
311
|
+
});
|
|
312
|
+
break;
|
|
313
|
+
case 'keyword':
|
|
314
|
+
case 'int':
|
|
315
|
+
completions.push({
|
|
316
|
+
label: value
|
|
317
|
+
});
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return completions;
|
|
322
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "traceQLHighlight", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return traceQLHighlight;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _highlight = require("@lezer/highlight");
|
|
24
|
+
const traceQLHighlight = (0, _highlight.styleTags)({
|
|
25
|
+
LineComment: _highlight.tags.comment,
|
|
26
|
+
'Parent Resource Span Identifier': _highlight.tags.labelName,
|
|
27
|
+
IntrinsicField: _highlight.tags.labelName,
|
|
28
|
+
String: _highlight.tags.string,
|
|
29
|
+
'Integer Float Duration': _highlight.tags.number,
|
|
30
|
+
Static: _highlight.tags.literal,
|
|
31
|
+
'Aggregate AggregateExpression': _highlight.tags.function(_highlight.tags.keyword),
|
|
32
|
+
'And Or': _highlight.tags.logicOperator,
|
|
33
|
+
'Gt Lt Desc Anc tilde ExperimentalOp': _highlight.tags.bitwiseOperator,
|
|
34
|
+
ComparisonOp: _highlight.tags.compareOperator,
|
|
35
|
+
Pipe: _highlight.tags.operator,
|
|
36
|
+
ScalarOp: _highlight.tags.arithmeticOperator,
|
|
37
|
+
'( )': _highlight.tags.paren,
|
|
38
|
+
'[ ]': _highlight.tags.squareBracket,
|
|
39
|
+
'{ }': _highlight.tags.brace,
|
|
40
|
+
'⚠': _highlight.tags.invalid
|
|
41
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
_export_star(require("./TraceQLEditor"), exports);
|
|
18
|
+
function _export_star(from, to) {
|
|
19
|
+
Object.keys(from).forEach(function(k) {
|
|
20
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
21
|
+
Object.defineProperty(to, k, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function() {
|
|
24
|
+
return from[k];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return from;
|
|
30
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -32,6 +32,7 @@ const _tempodatasource = require("./plugins/tempo-datasource");
|
|
|
32
32
|
const _TempoTraceQuery = require("./plugins/tempo-trace-query/TempoTraceQuery");
|
|
33
33
|
_export_star(require("./model/tempo-client"), exports);
|
|
34
34
|
_export_star(require("./model/tempo-selectors"), exports);
|
|
35
|
+
_export_star(require("./components/TraceQLExtension"), exports);
|
|
35
36
|
function _export_star(from, to) {
|
|
36
37
|
Object.keys(from).forEach(function(k) {
|
|
37
38
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
@@ -24,14 +24,20 @@ _export(exports, {
|
|
|
24
24
|
executeRequest: function() {
|
|
25
25
|
return executeRequest;
|
|
26
26
|
},
|
|
27
|
-
|
|
28
|
-
return
|
|
27
|
+
query: function() {
|
|
28
|
+
return query;
|
|
29
29
|
},
|
|
30
|
-
|
|
31
|
-
return
|
|
30
|
+
search: function() {
|
|
31
|
+
return search;
|
|
32
32
|
},
|
|
33
|
-
|
|
34
|
-
return
|
|
33
|
+
searchTagValues: function() {
|
|
34
|
+
return searchTagValues;
|
|
35
|
+
},
|
|
36
|
+
searchTags: function() {
|
|
37
|
+
return searchTags;
|
|
38
|
+
},
|
|
39
|
+
searchWithFallback: function() {
|
|
40
|
+
return searchWithFallback;
|
|
35
41
|
}
|
|
36
42
|
});
|
|
37
43
|
const _core = require("@perses-dev/core");
|
|
@@ -53,16 +59,16 @@ function fetchWithGet(apiURI, params, queryOptions) {
|
|
|
53
59
|
};
|
|
54
60
|
return executeRequest(url, init);
|
|
55
61
|
}
|
|
56
|
-
function
|
|
57
|
-
return fetchWithGet(
|
|
62
|
+
function search(params, queryOptions) {
|
|
63
|
+
return fetchWithGet('/api/search', params, queryOptions);
|
|
58
64
|
}
|
|
59
|
-
function
|
|
60
|
-
return fetchWithGet(`/api/traces/${
|
|
65
|
+
function query(params, queryOptions) {
|
|
66
|
+
return fetchWithGet(`/api/traces/${encodeURIComponent(params.traceId)}`, null, queryOptions);
|
|
61
67
|
}
|
|
62
|
-
async function
|
|
68
|
+
async function searchWithFallback(params, queryOptions) {
|
|
63
69
|
var _searchResponse_traces_;
|
|
64
70
|
// Get a list of traces that satisfy the query.
|
|
65
|
-
const searchResponse = await
|
|
71
|
+
const searchResponse = await search(params, queryOptions);
|
|
66
72
|
if (!searchResponse.traces || searchResponse.traces.length === 0) {
|
|
67
73
|
return {
|
|
68
74
|
traces: []
|
|
@@ -76,7 +82,9 @@ async function searchTraceQueryFallback(params, queryOptions) {
|
|
|
76
82
|
return {
|
|
77
83
|
traces: await Promise.all(searchResponse.traces.map(async (trace)=>{
|
|
78
84
|
const serviceStats = {};
|
|
79
|
-
const searchTraceIDResponse = await
|
|
85
|
+
const searchTraceIDResponse = await query({
|
|
86
|
+
traceId: trace.traceID
|
|
87
|
+
}, queryOptions);
|
|
80
88
|
// For every trace, get the full trace, and find the number of spans and errors.
|
|
81
89
|
for (const batch of searchTraceIDResponse.batches){
|
|
82
90
|
let serviceName = '?';
|
|
@@ -109,3 +117,10 @@ async function searchTraceQueryFallback(params, queryOptions) {
|
|
|
109
117
|
}))
|
|
110
118
|
};
|
|
111
119
|
}
|
|
120
|
+
function searchTags(params, queryOptions) {
|
|
121
|
+
return fetchWithGet('/api/v2/search/tags', params, queryOptions);
|
|
122
|
+
}
|
|
123
|
+
function searchTagValues(params, queryOptions) {
|
|
124
|
+
const { tag, ...rest } = params;
|
|
125
|
+
return fetchWithGet(`/api/v2/search/tag/${encodeURIComponent(tag)}/values`, rest, queryOptions);
|
|
126
|
+
}
|