Skip to content

Commit

Permalink
Add middleware to accept OTLP traces when uploaded
Browse files Browse the repository at this point in the history
Signed-off-by: Navin Shrinivas <karupal2002@gmail.com>
  • Loading branch information
NavinShrinivas committed Jan 31, 2024
1 parent 60e5ce4 commit ced668d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
3 changes: 3 additions & 0 deletions packages/jaeger-ui/src/api/jaeger.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ const JaegerAPI = {
fetchServiceOperations(serviceName) {
return getJSON(`${this.apiRoot}services/${encodeURIComponent(serviceName)}/operations`);
},
transformOTLP(traces) {
return getJSON(`${this.apiRoot}transform`, { method: 'POST', body: JSON.stringify(traces) });
},
fetchServiceServerOps(service) {
return getJSON(`${this.apiRoot}operations`, {
query: {
Expand Down
27 changes: 27 additions & 0 deletions packages/jaeger-ui/src/middlewares/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import { change } from 'redux-form';
import { replace } from 'redux-first-history';

import { searchTraces, fetchServiceOperations } from '../actions/jaeger-api';
import { loadJsonTraces } from '../actions/file-reader-api';
import { getUrl as getSearchUrl } from '../components/SearchTracePage/url';
import JaegerAPI from '../api/jaeger';

export { default as trackMiddleware } from './track';

Expand Down Expand Up @@ -45,4 +47,29 @@ export const historyUpdateMiddleware = store => next => action => {
return next(action);
};

export const transformOTLPMiddleware = store => next => action => {
if (action.type === String([`${loadJsonTraces}_FULFILLED`])) {
// Check if action.payload is OTLP and make API call if so
// We are allowed to change the action.payload here
//
if ('resourceSpans' in action.payload) {
JaegerAPI.transformOTLP(action.payload)
.then(result => {
const transformedAction = {
...action,
payload: result,
};
return next(transformedAction);
})
.catch(() => {
return next(action);
});
} else {
return next(action);
}
} else {
return next(action);
}
};

export const promise = promiseMiddleware;
2 changes: 1 addition & 1 deletion packages/jaeger-ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
// limitations under the License.
{
"extends": "../../tsconfig",
"include": ["src/**/*.tsx", "typings"],
"include": ["src/**/*.tsx", "typings"]
}
6 changes: 3 additions & 3 deletions packages/plexus/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
"jsx": "preserve",
"outDir": "lib",
"rootDir": "src",
"composite": true,
"composite": true
},
"include": [
"src",
// easier to add `./typings` here than deal with typeRoots, paths, etc.
"./typings",
],
"./typings"
]
}
10 changes: 5 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
"isolatedModules": true,
"declaration": true,
"emitDeclarationOnly": true,
"jsx": "preserve",
"jsx": "preserve"
},
"include": [],
"files": [],
"references": [
{
"path": "packages/jaeger-ui/tsconfig.lint.json",
"path": "packages/jaeger-ui/tsconfig.lint.json"
},
{
"path": "packages/plexus/tsconfig.json",
},
],
"path": "packages/plexus/tsconfig.json"
}
]
}

0 comments on commit ced668d

Please sign in to comment.