getsentry / sentry

Developer-first error tracking and performance monitoring
https://sentry.io
Other
39.09k stars 4.2k forks source link

Link to URLs from extra context #4636

Closed beheh closed 5 years ago

beheh commented 7 years ago

My organisation attaches various tracing URLs to exceptions in a Python (Django) application, linking to Cloudwatch logs or corresponding admin pages. We're using hosted Sentry.

We've accidentally been using the user context so far for these, which meant the links appeared in the "User" section on the exception page and had the small, clickable "external link" icon.

I've now moved the attached URLs to the extra context, and while the URLs are now shown in the "Additional Data" section, they no longer feature the clickable icon directly opening that link. Additionally, the user context has been stripping the python unicode "u" prefix and the surrounding quotes, which the extra context does not.

I assume it's a bug that the extra context is behaving differently here.

markstory commented 5 years ago

I took a look into this and this functionality is in sentry.io, and will be in the next on-premise release if it is not already there too.

beheh commented 5 years ago

Does that mean this should be fixed as of right now on sentry.io, or only in an upcoming deploy there? I'm still seeing a scrollable text field and no clickable external link icon there:

link

markstory commented 5 years ago

Which SDK are you using to record that information? I tried reproducing this problem with the PHP SDK and the following extra context:

$sentry->extra_context([
        'list' => ['fish', 'in', 'a', 'bowl'],
        'nested_url' => ['nope', 'http://example.org/nested'],
        'toplevel' => ['https://example.org/top'],
);

Results in the following on my issue

screen shot 2018-12-12 at 9 42 06 am

which contains working external link icons. I'll see if the presence of a querystring or document fragment breaks our autolinking.

markstory commented 5 years ago

Basic query strings and fragments also work for me:

screen shot 2018-12-12 at 2 12 19 pm
beheh commented 5 years ago

We are using the (old) Python SDK:

extra_context = {
    "aws_log_group_name": context.log_group_name,
    "aws_log_stream_name": context.log_stream_name,
    "aws_cloudwatch_url": get_cloudwatch_url(context),
    "event": event,
}

https://github.com/HearthSim/HSReplay.net/blob/54a5e372e6ddd870fa102c7e827c359c28b81187/hsreplaynet/utils/instrumentation.py#L110-L115

...after we build it from a basic template string:

def get_cloudwatch_url(context, region="us-east-1"):
    baseurl = "https://console.aws.amazon.com/cloudwatch/home"
    tpl = "?region=%s#logEventViewer:group=%s;stream=%s"
    return baseurl + tpl % (
        region, context.log_group_name, context.log_stream_name,
    )

https://github.com/HearthSim/HSReplay.net/blob/54a5e372e6ddd870fa102c7e827c359c28b81187/hsreplaynet/utils/instrumentation.py#L48-L53

I wonder why the URL has extra single quotes in our sentry.io screenshot, but not in yours?

markstory commented 5 years ago

It could be how the raven library converts data before sending it to sentry. I will see if I can reproduce missing links from a python script.

markstory commented 5 years ago

I was able to reproduce this problem with the old python SDK. That SDK casts string data into their repr value. However, the new sentry_sdk library does not do this and allows autolinks to be created. You should consider upgrading if autolinking in extra_context is important to you.

beheh commented 5 years ago

OK, great! We're in the process of updating it. Thanks for the help.