grafana/public/app/features/query/components/QueryErrorAlert.tsx
Gábor Farkas 4ded937c79
Show traceids for failing and successful requests (#64903)
* tracing: show backend trace ids in frontend

* better trace id naming

Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>

* better trace id naming

Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>

* better trace id naming

Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>

* added feature flag

* bind functionality to the feature flag

* use non-generic name for traceid header

* fixed tests

* loki: do not create empty fields

* do not add empty fields

* fixed graphite test mock data

* added unit-tests to queryResponse

* added unit-tests for backend_srv

* more typescript-friendly check

* added unit-tests for runRequest

---------

Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>
2023-04-05 09:13:24 +02:00

51 lines
1.3 KiB
TypeScript

import { css } from '@emotion/css';
import React from 'react';
import { DataQueryError, GrafanaTheme2 } from '@grafana/data';
import { config } from '@grafana/runtime';
import { Icon, useStyles2 } from '@grafana/ui';
export interface Props {
error: DataQueryError;
}
export function QueryErrorAlert({ error }: Props) {
const styles = useStyles2(getStyles);
const message = error?.message ?? error?.data?.message ?? 'Query error';
return (
<div className={styles.wrapper}>
<div className={styles.icon}>
<Icon name="exclamation-triangle" />
</div>
<div className={styles.message}>
{message}
{config.featureToggles.showTraceId && error.traceId != null && (
<>
<br /> <span>(Trace ID: {error.traceId})</span>
</>
)}
</div>
</div>
);
}
const getStyles = (theme: GrafanaTheme2) => ({
wrapper: css({
marginTop: theme.spacing(0.5),
background: theme.colors.background.secondary,
display: 'flex',
}),
icon: css({
background: theme.colors.error.main,
color: theme.colors.error.contrastText,
padding: theme.spacing(1),
}),
message: css({
fontSize: theme.typography.bodySmall.fontSize,
fontFamily: theme.typography.fontFamilyMonospace,
padding: theme.spacing(1),
}),
});