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 b99756d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 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;

0 comments on commit b99756d

Please sign in to comment.