Skip to content

Commit

Permalink
Refactor navigation (#56)
Browse files Browse the repository at this point in the history
* Refactor navigation

* Do not clear span data on span detail collapse
  • Loading branch information
kshmidt-digma authored Jul 2, 2024
1 parent e14d346 commit 23b04e9
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 23 deletions.
11 changes: 8 additions & 3 deletions packages/jaeger-ui/src/api/digma/ActionDispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionListener } from './types';
import { ActionListener, DigmaMessageError } from './types';

class ActionDispatcher {
private actions: {
Expand Down Expand Up @@ -27,9 +27,14 @@ class ActionDispatcher {
}
}

public dispatch(timeStamp: number, type: string, data?: unknown): void {
public dispatch(
timeStamp: number,
type: string,
data: unknown,
error: DigmaMessageError | undefined
): void {
if (this.actions[type]) {
this.actions[type].forEach(fn => fn(data, timeStamp));
this.actions[type].forEach(fn => fn(data, timeStamp, error));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jaeger-ui/src/api/digma/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { addActionPrefix } from './addActionPrefix';

export const actions = {
GO_TO_SPAN: 'GO_TO_SPAN',
GO_TO_INSIGHTS: 'GO_TO_INSIGHTS',
GET_SPANS_DATA: 'GET_SPANS_DATA',
SET_SPANS_DATA: 'SET_SPANS_DATA',
CLEAR: 'CLEAR',
Expand All @@ -11,5 +10,6 @@ export const actions = {
const GLOBAL_ACTION_PREFIX = 'GLOBAL';

export const globalActions = addActionPrefix(GLOBAL_ACTION_PREFIX, {
CHANGE_SCOPE: 'CHANGE_SCOPE',
OPEN_URL_IN_DEFAULT_BROWSER: 'OPEN_URL_IN_DEFAULT_BROWSER',
});
2 changes: 1 addition & 1 deletion packages/jaeger-ui/src/api/digma/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const initializeDigmaMessageListener = (dispatcher: ActionDispatcher) =>

export const sendMessage = <T>(message: IDigmaOutgoingMessageData<T>): string | undefined => {
logger.debug(
`Message to sent: ${message.action}
`Message to send: ${message.action}
Raw message: %O`,
message
);
Expand Down
31 changes: 30 additions & 1 deletion packages/jaeger-ui/src/api/digma/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { InsightType } from '../../components/common/InsightIcon/types';
import { IDigmaSpanData } from '../../utils/getSpanDataForDigma';

export type ActionListener = (data: unknown, timeStamp: number) => void;
export type ActionListener = (data: unknown, timeStamp: number, error: DigmaMessageError | undefined) => void;

export type DigmaMessageError = {
message: string;
};

export interface IDigmaIncomingMessageData {
type: 'digma';
action: string;
payload?: unknown;
error?: DigmaMessageError;
}

export interface IDigmaOutgoingMessageData<T> {
Expand All @@ -25,4 +31,27 @@ interface ISpanInfo {
insights: ISpanInsight[];
}

export type GoToSpanPayload = IDigmaSpanData;

export type GoToInsightsPayload = IDigmaSpanData;

export type GetSpansDataPayload = { spans: IDigmaSpanData[] };

export type SetSpansDataPayload = Record<string, ISpanInfo>;

export type ChangeScopePayload = {
span: {
spanCodeObjectId: string;
} | null;
forceNavigation?: boolean;
environmentId?: string;
context?: {
event: string;
payload?: Record<string, unknown>;
};
};

export type OpenURLInDefaultBrowserPayload = {
url: string;
title?: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import './TracePageHeader.css';
import ExternalLinks from '../../common/ExternalLinks';
import ZoomControls from './ZoomControls';
import { globalActions } from '../../../api/digma/actions';
import { OpenURLInDefaultBrowserPayload } from '../../../api/digma/types';

type TracePageHeaderEmbedProps = {
canCollapse: boolean;
Expand Down Expand Up @@ -159,7 +160,7 @@ export function TracePageHeaderFn(props: TracePageHeaderEmbedProps & { forwarded

const handleStandaloneLinkClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();
window.sendMessageToDigma({
window.sendMessageToDigma<OpenURLInDefaultBrowserPayload>({
action: globalActions.OPEN_URL_IN_DEFAULT_BROWSER,
payload: {
url: `${window.apiBaseUrl}${window.location.pathname}${window.location.search}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ import DetailState from './DetailState';
import { formatDuration } from '../utils';
import CopyIcon from '../../../common/CopyIcon';
import LabeledList from '../../../common/LabeledList';
import { actions } from '../../../../api/digma/actions';
import { actions, globalActions } from '../../../../api/digma/actions';
import dispatcher from '../../../../api/digma/dispatcher';
import { state as globalState } from '../../../../api/digma/state';
import { ISpanInsight, SetSpansDataPayload } from '../../../../api/digma/types';
import {
ChangeScopePayload,
GoToSpanPayload,
ISpanInsight,
SetSpansDataPayload,
} from '../../../../api/digma/types';
import { getInsightTypeInfo, getInsightTypeOrderPriority } from '../../../common/InsightIcon/utils';
import { InsightIcon } from '../../../common/InsightIcon';
import Button from '../../../common/Button';
Expand Down Expand Up @@ -77,9 +82,6 @@ export default class SpanDetail extends React.Component<SpanDetailProps, SpanDet

componentWillUnmount() {
dispatcher.removeActionListener(actions.SET_SPANS_DATA, this._updateSpanInfo);
window.sendMessageToDigma({
type: actions.CLEAR,
});
}

_sortInsightsByImportance(insights: ISpanInsight[]): ISpanInsight[] {
Expand All @@ -101,18 +103,30 @@ export default class SpanDetail extends React.Component<SpanDetailProps, SpanDet
_handleCodeButtonClick() {
const spanInfo = getSpanDataForDigma(this.props.span);

window.sendMessageToDigma({
window.sendMessageToDigma<GoToSpanPayload>({
action: actions.GO_TO_SPAN,
payload: spanInfo,
});
}

_handleSpanNameLinkClick() {
const spanInfo = getSpanDataForDigma(this.props.span);
const spanInfo = getSpanDataForDigma(this.props.span, true);

window.sendMessageToDigma({
action: actions.GO_TO_INSIGHTS,
payload: spanInfo,
if (!spanInfo.spanCodeObjectId) {
return;
}

window.sendMessageToDigma<ChangeScopePayload>({
action: globalActions.CHANGE_SCOPE,
payload: {
span: {
spanCodeObjectId: spanInfo.spanCodeObjectId,
},
environmentId: spanInfo.environmentId,
context: {
event: 'JAEGER/SPAN_LINK_CLICKED',
},
},
});
}

Expand Down
5 changes: 3 additions & 2 deletions packages/jaeger-ui/src/components/TracePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import TraceFlamegraph from './TraceFlamegraph/index';
import { TraceGraphConfig } from '../../types/config';
import { actions } from '../../api/digma/actions';
import getSpanDataForDigma from '../../utils/getSpanDataForDigma';
import { GetSpansDataPayload } from '../../api/digma/types';

import './index.css';

Expand Down Expand Up @@ -224,10 +225,10 @@ export class TracePageImpl extends React.PureComponent<TProps, TState> {

getSpansWithResolvedLocations(trace: Trace) {
// Get all the trace spans and send it Digma IDE plugin
window.sendMessageToDigma({
window.sendMessageToDigma<GetSpansDataPayload>({
action: actions.GET_SPANS_DATA,
payload: {
spans: trace.spans.map(getSpanDataForDigma).filter(span => span.instrumentationLibrary),
spans: trace.spans.map(x => getSpanDataForDigma(x)).filter(span => span.instrumentationLibrary),
},
});
}
Expand Down
6 changes: 4 additions & 2 deletions packages/jaeger-ui/src/utils/getSpanDataForDigma.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Span } from '../types/trace';

interface IDigmaSpanData {
export interface IDigmaSpanData {
id: string;
name: string;
serviceName: string;
Expand All @@ -10,9 +10,10 @@ interface IDigmaSpanData {
spanCodeObjectId?: string;
methodCodeObjectId?: string;
environment?: string;
environmentId?: string;
}

const getSpanDataForDigma = (span: Span): IDigmaSpanData => {
const getSpanDataForDigma = (span: Span, withEnvironmentId: boolean | undefined = false): IDigmaSpanData => {
const tagsToGet = {
instrumentationLibrary: 'otel.library.name',
function: 'code.function',
Expand All @@ -23,6 +24,7 @@ const getSpanDataForDigma = (span: Span): IDigmaSpanData => {

const processTagsToGet = {
environment: 'digma.environment',
...(withEnvironmentId ? { environmentId: 'digma.environment.id' } : {}),
};

const tagsValues = Object.entries(tagsToGet).reduce((acc, [key, value]) => {
Expand Down
6 changes: 4 additions & 2 deletions packages/jaeger-ui/typings/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ declare interface Window {
onFailure: (error_code, error_message) => void;
}) => string;
cefQueryCancel?: (request_id: string) => void;
sendMessageToDigma: (message) => string | undefined;
sendMessageToDigma: <T>(
message: { action: string; payload?: T } /* IDigmaOutgoingMessageData */
) => string | undefined;
cancelMessageToDigma: (request_id: string) => void;
platform?: unknown;
apiBaseUrl?: unknown;
Expand All @@ -40,7 +42,7 @@ declare interface Window {
isUserDefinedJaegerQueryURL?: unknown;
staticPath?: unknown;
enableZoomControls?: unknown;
isLoggingEnabled?: boolean;
isLoggingEnabled?: unknown;
}

declare const __REACT_APP_GA_DEBUG__: string | undefined;
Expand Down

0 comments on commit 23b04e9

Please sign in to comment.