Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor navigation #56

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
});
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 @@ -78,7 +83,7 @@ export default class SpanDetail extends React.Component<SpanDetailProps, SpanDet
componentWillUnmount() {
dispatcher.removeActionListener(actions.SET_SPANS_DATA, this._updateSpanInfo);
window.sendMessageToDigma({
type: actions.CLEAR,
action: actions.CLEAR,
});
}

Expand All @@ -101,7 +106,7 @@ 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,
});
Expand All @@ -110,9 +115,21 @@ export default class SpanDetail extends React.Component<SpanDetailProps, SpanDet
_handleSpanNameLinkClick() {
const spanInfo = getSpanDataForDigma(this.props.span);

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.environment,
context: {
event: 'JAEGER/SPAN_LINK_CLICKED',
},
},
});
}

Expand Down
3 changes: 2 additions & 1 deletion 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,7 +225,7 @@ 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),
Expand Down
4 changes: 2 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 @@ -22,7 +22,7 @@ const getSpanDataForDigma = (span: Span): IDigmaSpanData => {
};

const processTagsToGet = {
environment: 'digma.environment',
environment: '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