-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add links to logs from trace #93
Draft
aocenas
wants to merge
26
commits into
main
Choose a base branch
from
aocenas/trace-to-logs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+302
−126
Draft
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e780c60
update deps and fix errors
aocenas 267a1ea
Add trace to logs section
aocenas 8f1eadc
Merge branch 'master' into aocenas/trace-to-logs
aocenas 89ae5b2
Remove unused code
aocenas 332b772
Add links
aocenas 4ea69dd
Merge branch 'master' into aocenas/trace-to-logs
aocenas 8e42193
Convert to milliseconds
aocenas c32aae6
Merge branch 'aocenas/fix-times-2' into aocenas/trace-to-logs
aocenas 1594cf7
Merge branch 'master' into aocenas/trace-to-logs
aocenas 95a8377
Add filter by request id to log links
aocenas 60317a3
Merge remote-tracking branch 'origin/aocenas/trace-to-logs' into aoce…
aocenas c221707
Fix transform test
aocenas 24ad6af
Fix data source test
aocenas cdca104
Fix merge conflict
sarahzinger 7b3ed0c
Only handle lambdas for now
sarahzinger 2974ac6
Do not fetch account id if not on service map page
sarahzinger e305004
Merge branch 'main' into aocenas/trace-to-logs
sarahzinger 261d810
Merge branch 'refactor-account-dropdown' into aocenas/trace-to-logs
sarahzinger 24918a0
Lint fix
sarahzinger 9032c45
Merge branch 'refactor-account-dropdown' into aocenas/trace-to-logs
sarahzinger 1749a3c
Lint
sarahzinger ff5c348
Merge branch 'main' into aocenas/trace-to-logs
sarahzinger c76dd3d
Merge branch 'main' into aocenas/trace-to-logs
sarahzinger 6f993a2
Add support for API gateway
sarahzinger 2ee7bdf
Merge conflict
sarahzinger bb4b4fc
Test fix
sarahzinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { css } from '@emotion/css'; | ||
import { GrafanaTheme } from '@grafana/data'; | ||
import { DataSourcePicker } from '@grafana/runtime'; | ||
import { InlineField, InlineFieldRow, useStyles } from '@grafana/ui'; | ||
import React from 'react'; | ||
|
||
interface Props { | ||
datasourceUid?: string; | ||
onChange: (uid: string) => void; | ||
} | ||
|
||
export function TraceToLogs({ datasourceUid, onChange }: Props) { | ||
const styles = useStyles(getStyles); | ||
|
||
return ( | ||
<div className={css({ width: '100%' })}> | ||
<h3 className="page-heading">Trace to logs</h3> | ||
|
||
<div className={styles.infoText}> | ||
Trace to logs let's you navigate from a trace span to the selected data source's log. | ||
</div> | ||
|
||
<InlineFieldRow> | ||
<InlineField tooltip="The data source the trace is going to navigate to" label="Data source" labelWidth={26}> | ||
<DataSourcePicker | ||
pluginId="cloudwatch" | ||
current={datasourceUid} | ||
noDefault={true} | ||
width={40} | ||
onChange={(ds) => onChange(ds.uid)} | ||
/> | ||
</InlineField> | ||
</InlineFieldRow> | ||
</div> | ||
); | ||
} | ||
|
||
const getStyles = (theme: GrafanaTheme) => ({ | ||
infoText: css` | ||
padding-bottom: ${theme.spacing.md}; | ||
color: ${theme.colors.textSemiWeak}; | ||
`, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
import { XrayQuery, XrayQueryType } from '../types'; | ||
import { DataSourceInstanceSettings } from '@grafana/data'; | ||
import { DataFrame, DataLink, DataSourceInstanceSettings } from '@grafana/data'; | ||
import { getDataSourceSrv } from '@grafana/runtime'; | ||
|
||
export function makeLinks(itemQuery: string, instanceSettings: DataSourceInstanceSettings, dataQuery?: XrayQuery) { | ||
/** | ||
* Create links that will be shown when clicked on a service in service map. They target the same data source but | ||
* queries for traces related to that particular service | ||
* @param itemQuery String query part that should filter a particular service | ||
* @param instanceSettings | ||
* @param dataQuery Existing query to pass on any additional query data so they stay the same, like region. | ||
*/ | ||
export function makeServiceMapLinks( | ||
itemQuery: string, | ||
instanceSettings: DataSourceInstanceSettings, | ||
dataQuery?: XrayQuery | ||
) { | ||
const makeLink = linkFactory(itemQuery, instanceSettings, dataQuery); | ||
return [ | ||
makeLink('Traces/All', XrayQueryType.getTraceSummaries), | ||
|
@@ -15,8 +27,52 @@ export function makeLinks(itemQuery: string, instanceSettings: DataSourceInstanc | |
]; | ||
} | ||
|
||
export async function addTraceToLogsLinks(frame: DataFrame, region?: string, datasourceUid?: string) { | ||
if (!datasourceUid) { | ||
return; | ||
} | ||
try { | ||
const spanField = frame.fields.find((f) => f.name === 'spanID')!; | ||
const requestIdField = frame.fields.find((f) => f.name === '__request_id')!; | ||
const link = await makeTraceToLogsLink(datasourceUid, region, { | ||
hasRequestId: Boolean(requestIdField.values.get(0)), | ||
}); | ||
spanField.config.links = [link]; | ||
} catch (error) { | ||
// There are some things that can go wrong like datasourceUID not existing anymore etc. Does not seem useful to | ||
// error the whole query in that case so we will just skip the links. | ||
console.error(error); | ||
} | ||
} | ||
|
||
async function makeTraceToLogsLink( | ||
datasourceUid: string, | ||
region = 'default', | ||
options: { hasRequestId: boolean } | ||
): Promise<DataLink> { | ||
const logsDS = await getDataSourceSrv().get(datasourceUid); | ||
const filter = options.hasRequestId | ||
? 'filter @requestId = "${__data.fields.__request_id}" or @message like "${__data.fields.traceID}"' | ||
: 'filter @message like "${__data.fields.traceID}"'; | ||
return { | ||
title: 'CloudWatch Logs', | ||
url: '', | ||
internal: { | ||
query: { | ||
region, | ||
queryMode: 'Logs', | ||
// Just use the data from the data frame. Needs to be filled in during transform. | ||
logGroupNames: ['${__data.fields.__log_group}'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We assume the __log_group field is already present. |
||
expression: `fields @message | ${filter}`, | ||
}, | ||
datasourceUid, | ||
datasourceName: logsDS.name, | ||
}, | ||
}; | ||
} | ||
|
||
function linkFactory(itemQuery: string, instanceSettings: DataSourceInstanceSettings, dataQuery?: XrayQuery) { | ||
return (title: string, queryType: XrayQueryType, queryFilter?: string) => { | ||
return (title: string, queryType: XrayQueryType, queryFilter?: string): DataLink => { | ||
return { | ||
title, | ||
url: '', | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a filter that also x-ray uses when looking for logs from a trace in their UI.