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

added function to show full traceID in #2536

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { formatDuration } from '../../../utils/date';

import { FetchedState, TNil } from '../../../types';
import { ApiError } from '../../../types/api-error';
import TraceId from '../../common/TraceId';

import './TraceHeader.css';

Expand Down Expand Up @@ -86,9 +87,7 @@ export default function TraceHeader(props: Props) {
{traceID ? (
<React.Fragment>
<TraceName key="name" traceName={traceName} error={error} state={state} />{' '}
<small key="id" className="u-tx-muted ub-pr2">
{traceID.slice(0, 7)}
</small>
<TraceId traceId={traceID} />
<TraceTimelineLink traceID={traceID} />
</React.Fragment>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { getTraceLinks } from '../../../model/link-patterns';
import './TracePageHeader.css';
import ExternalLinks from '../../common/ExternalLinks';
import { getTargetEmptyOrBlank } from '../../../utils/config/get-target';
import TraceId from '../../common/TraceId';

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

const title = (
<h1 className={`TracePageHeader--title ${canCollapse ? 'is-collapsible' : ''}`}>
<TraceName traceName={trace.traceName} /> <small className="u-tx-muted">{traceShortID}</small>
<TraceName traceName={trace.traceName} /> <TraceId traceId={trace.traceID} />
</h1>
);

Expand Down
28 changes: 28 additions & 0 deletions packages/jaeger-ui/src/components/common/TraceId.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright (c) 2018 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
.TraceIDLength {
display: inline-block;
vertical-align: middle;
}
.TraceIDLength--short {
font-size: 18px;
padding: 3px 4px;
}
.TraceIDLength--full {
font-size: 16px;
padding: 3px 4px;
letter-spacing: 0.2px;
}
100 changes: 100 additions & 0 deletions packages/jaeger-ui/src/components/common/TraceId.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright (c) 2023 The Jaeger Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import React from 'react';
import { shallow } from 'enzyme';
import { TraceId } from './TraceId';
import { getConfigValue } from '../../utils/config/get-config';

jest.mock('../../utils/config/get-config', () => ({
getConfigValue: jest.fn(),
}));

describe('TraceIdDisplayLength', () => {
const DEFAULT_LENGTH = 7;
const MOCK_TRACE_ID = '12345678901234567890';
const CUSTOM_CLASS = 'custom-class';

let wrapper;

const defaultProps = {
traceId: MOCK_TRACE_ID,
};

beforeEach(() => {
jest.clearAllMocks();
});

const createWrapper = (props = {}) => {
return shallow(<TraceId {...defaultProps} {...props} />);
};

describe('TraceIdDisplayLength Component', () => {
it('renders the default traceIdLength 7', () => {
getConfigValue.mockReturnValue(undefined);
wrapper = createWrapper();

const displayedText = wrapper.text();
expect(displayedText).toEqual(MOCK_TRACE_ID.slice(0, DEFAULT_LENGTH));
});

it('renders the config length when provided', () => {
const configuredLength = 5;
getConfigValue.mockReturnValue(configuredLength);
wrapper = createWrapper();

const displayedText = wrapper.text();
expect(displayedText).toEqual(MOCK_TRACE_ID.slice(0, configuredLength));
});
});

describe('Edge case handling', () => {
it('renders the full traceId when it is shorter then configured length', () => {
const shortTraceId = '12345';
const configuredLength = 10;
getConfigValue.mockReturnValue(configuredLength);

wrapper = createWrapper({ traceId: shortTraceId });
expect(wrapper.text()).toEqual(shortTraceId);
});

it('renders when traceId is undefiend', () => {
wrapper = createWrapper({ traceId: '' });
expect(wrapper.text()).toEqual('');
});
});

describe('Style handling', () => {
it('applies custom className when provided', () => {
wrapper = createWrapper({ className: CUSTOM_CLASS });
expect(wrapper.hasClass(CUSTOM_CLASS)).toBe(true);
});

it('default classes for styling', () => {
wrapper = createWrapper();
expect(wrapper.hasClass('TraceIDLength')).toBe(true);
expect(wrapper.hasClass('u-tx-muted')).toBe(true);
});

it('adds a length-based class depending on the configuration', () => {
getConfigValue.mockReturnValue(DEFAULT_LENGTH);
wrapper = createWrapper();
expect(wrapper.hasClass('TraceIDLength--short')).toBe(true);

getConfigValue.mockReturnValue(32);
wrapper = createWrapper();
expect(wrapper.hasClass('TraceIDLength--full')).toBe(true);
});
});
});
34 changes: 34 additions & 0 deletions packages/jaeger-ui/src/components/common/TraceId.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2023 The Jaeger Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import React from 'react';
import { getConfigValue } from '../../utils/config/get-config';
import './TraceId.css';

type Props = {
traceId: string;
className?: string;
};

export function TraceId({ traceId, className = '' }: Props) {
const traceIdDisplayLength = getConfigValue('traceIdDisplayLength') || 7;
const traceIdDisplay = traceId ? traceId.slice(0, traceIdDisplayLength) : '';
const lengthClass = traceIdDisplayLength === 7 ? 'TraceIDLength--short' : 'TraceIDLength--full';

return (
<small className={`TraceIDLength ${lengthClass} u-tx-muted ub-pr2 ${className} `}>{traceIdDisplay}</small>
);
}

export default TraceId;
1 change: 1 addition & 0 deletions packages/jaeger-ui/src/constants/default-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const defaultConfig: Config = {
},
maxLimit: 1500,
},
traceIdDisplayLength: 7,
storageCapabilities: {
archiveStorage: false,
},
Expand Down
3 changes: 3 additions & 0 deletions packages/jaeger-ui/src/types/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export type Config = {
// TODO when is it useful?
scripts?: readonly TScript[];

// traceIDLength controls the length of the trace ID displayed in the UI.
traceIdDisplayLength?: number;

// storage capabilities given by the query service.
storageCapabilities?: StorageCapabilities;

Expand Down
Loading