Skip to content

Commit

Permalink
Merge pull request #22 from digma-ai/fix/span-code-object-id
Browse files Browse the repository at this point in the history
Add code object ids to the GET_SPANS message
  • Loading branch information
kshmidt-digma authored Jun 14, 2023
2 parents 6bf8e76 + 0380144 commit 4ddee76
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { getInsightTypeInfo, getInsightTypeOrderPriority } from '../../../common
import { InsightIcon } from '../../../common/InsightIcon';
import Button from '../../../common/Button';
import { CrosshairIcon } from '../../../common/icons/CrosshairIcon';
import getSpanDataForDigma from '../../../../utils/getSpanDataForDigma';

import { TNil } from '../../../../types';
import { KeyValuePair, Link, Log, Span } from '../../../../types/trace';
Expand Down Expand Up @@ -63,7 +64,6 @@ export default class SpanDetail extends React.Component<SpanDetailProps, SpanDet
this._updateSpanInfo = this._updateSpanInfo.bind(this);
this._handleCodeButtonClick = this._handleCodeButtonClick.bind(this);
this._handleSpanNameLinkClick = this._handleSpanNameLinkClick.bind(this);
this._prepareSpanInfo = this._prepareSpanInfo.bind(this);
const span = globalState.spans[props.span.spanID];
this.state = {
hasCodeLocation: Boolean(span && span.hasCodeLocation),
Expand Down Expand Up @@ -96,29 +96,8 @@ export default class SpanDetail extends React.Component<SpanDetailProps, SpanDet
});
}

_prepareSpanInfo() {
const tagsToGet = {
instrumentationLibrary: 'otel.library.name',
function: 'code.function',
namespace: 'code.namespace',
spanCodeObjectIdTag: 'digma.span.code.object.id',
methodCodeObjectId: 'digma.method.code.object.id',
};

const tagsValues = Object.entries(tagsToGet).reduce((acc, [key, value]) => {
const tag = this.props.span.tags.find((x: any) => x.key === value);
return tag ? { ...acc, [key]: tag.value } : acc;
}, {});

return {
...tagsValues,
id: this.props.span.spanID,
name: this.props.span.operationName,
};
}

_handleCodeButtonClick() {
const spanInfo = this._prepareSpanInfo();
const spanInfo = getSpanDataForDigma(this.props.span);

window.sendMessageToDigma({
action: actions.GO_TO_SPAN,
Expand All @@ -127,7 +106,7 @@ export default class SpanDetail extends React.Component<SpanDetailProps, SpanDet
}

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

window.sendMessageToDigma({
action: actions.GO_TO_INSIGHTS,
Expand Down Expand Up @@ -170,10 +149,7 @@ export default class SpanDetail extends React.Component<SpanDetailProps, SpanDet
},
];
const deepLinkCopyText = `${window.location.origin}${window.location.pathname}?uiFind=${spanID}`;
const isInstrumentationLibraryPresent = Object.prototype.hasOwnProperty.call(
this._prepareSpanInfo(),
'instrumentationLibrary'
);
const isInstrumentationLibraryPresent = getSpanDataForDigma(this.props.span).instrumentationLibrary;

return (
<div>
Expand Down
17 changes: 2 additions & 15 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 { dispatcher } from '../../api/digma/dispatcher';
import getSpanDataForDigma from '../../utils/getSpanDataForDigma';

import './index.css';

Expand Down Expand Up @@ -225,21 +226,7 @@ export class TracePageImpl extends React.PureComponent<TProps, TState> {
window.sendMessageToDigma({
action: actions.GET_SPANS_DATA,
payload: {
spans: trace.spans
.map(span => {
const otelLibraryNameTag = span.tags.find(tag => tag.key === 'otel.library.name');
const functionTag = span.tags.find(tag => tag.key === 'code.function');
const namespaceTag = span.tags.find(tag => tag.key === 'code.namespace');

return {
id: span.spanID,
name: span.operationName,
instrumentationLibrary: otelLibraryNameTag && otelLibraryNameTag.value,
...(functionTag ? { function: functionTag.value } : {}),
...(namespaceTag ? { namespace: namespaceTag.value } : {}),
};
})
.filter(span => span.instrumentationLibrary),
spans: trace.spans.map(getSpanDataForDigma).filter(span => span.instrumentationLibrary),
},
});
}
Expand Down
34 changes: 34 additions & 0 deletions packages/jaeger-ui/src/utils/getSpanDataForDigma.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Span } from '../types/trace';

interface IDigmaSpanData {
id: string;
name: string;
instrumentationLibrary?: string;
function?: string;
namespace?: string;
spanCodeObjectId?: string;
methodCodeObjectId?: string;
}

const getSpanDataForDigma = (span: Span): IDigmaSpanData => {
const tagsToGet: Omit<IDigmaSpanData, 'id' | 'name'> = {
instrumentationLibrary: 'otel.library.name',
function: 'code.function',
namespace: 'code.namespace',
spanCodeObjectId: 'digma.span.code.object.id',
methodCodeObjectId: 'digma.method.code.object.id',
};

const tagsValues = Object.entries(tagsToGet).reduce((acc, [key, value]) => {
const tag = span.tags.find((x: any) => x.key === value);
return tag ? { ...acc, [key]: tag.value } : acc;
}, {});

return {
...tagsValues,
id: span.spanID,
name: span.operationName,
};
};

export default getSpanDataForDigma;

0 comments on commit 4ddee76

Please sign in to comment.