Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

feat: Sentry context #237

Merged
merged 8 commits into from
Apr 20, 2018
Merged

feat: Sentry context #237

merged 8 commits into from
Apr 20, 2018

Conversation

bruno-garcia
Copy link
Member

  • Payload creating has runtime detection
  • Context is built lazily on first event
  • Root context is closed per event to avoid sys calls required to build it
  • .NET Framework 4.7.1 added to support NET Standard 2.0 paths (RuntimeInformation)
  • Warnings over obsolete calls removed from test projects
  • Nancy targets net471 also
  • Json.NET indirect reference to Nancy

* Context is built lazily on first event
* Root context is closed per event to avoid sys calls required to build
it
* .NET Framework 4.7.1 added to support NET Standar 2.0 paths
(RuntimeInformation)
* Warnings over obsolete calls removed from test projects
* Nancy targets net471 also
* Json.NET indirect reference to Nancy
@bruno-garcia bruno-garcia changed the title Sentry context WIP: Sentry context Apr 18, 2018
@bruno-garcia bruno-garcia changed the title WIP: Sentry context feat: Sentry context Apr 18, 2018
Copy link
Member

@jan-auer jan-auer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this. Note that to be fully API compatible, contexts could theoretically be renamed, for example:

{
  "runtime": {
    "name": ".NET Framework"
  },
  "asp": {
    "type": "runtime",
    "name": "ASP.NET"
  }
}

Copy link
Contributor

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great additions. I only have a few minor comments.

app.Version = asm.Version?.ToString();
}

using (var proc = Process.GetCurrentProcess())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it wise to .Dispose() the current process?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This instance was created by me at this location and should be disposed when not needed.

/// Retrieves the architecture of this device.
/// </summary>
/// <returns>Arch or null if unknown</returns>
internal static string GetArchitecture() =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these internal methods only seem to be used in a private scope, so can they be changed to private instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I made them internal for testing but I'm just covering them through testing the whole Device at the end. I'll make them private.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is actually used by tests*

/// <seealso href="https://docs.sentry.io/clientdev/interfaces/contexts/"/>
public Contexts Contexts
{
get { return this.contexts; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just add an internal set; to this property so we get rid of the field?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

return entryMethod?.Module?.Assembly?.GetName();
}

internal static MethodBase GetApplicationEntryMethod()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if (displayName != null)
{
monoVersion = displayName.Invoke(null, null) as string;
if (monoVersion != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't all of these null checks be collapsed into a chained null propagation (?.) expression?

Copy link
Member Author

@bruno-garcia bruno-garcia Apr 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was afraid it'd be less readable but looks fine. Will change.

{
var sut = App.Create();

Assert.True(sut.StartTime.HasValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Assert.That(app.StartTime.HasValue, Is.True) reads better.

var sut = App.Create();

Assert.True(sut.StartTime.HasValue);
Assert.AreNotEqual(default(DateTimeOffset), sut.StartTime.Value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Assert.That(app.StartTime.Value, Is.Not.EqualTo(default(DateTimeOffset)) reads better.


Assert.True(sut.StartTime.HasValue);
Assert.AreNotEqual(default(DateTimeOffset), sut.StartTime.Value);
Assert.Greater(DateTimeOffset.UtcNow, sut.StartTime);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Assert.That(app.StartTime, Is.GreaterThan(DateTimeOffset.UtcNow)) reads better.

{
var sut = App.Create();

Assert.NotNull(sut.Version);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Assert.That(app.Version, Is.Not.Null) reads better.

Assert.That(actual, Is.EqualTo(@case.ExpectedSerializationOutput));
}

public static IEnumerable<object[]> TestCases()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bruno-garcia
Copy link
Member Author

@asbjornu could you please check again?

@asbjornu
Copy link
Contributor

@bruno-garcia: GetArchitecture and GetApplicationEntryMethod are still internal, but otherwise I think it looks good.

@bruno-garcia
Copy link
Member Author

@asbjornu I commented on the review: It's to be accessed by the Unit testing library.

@bruno-garcia
Copy link
Member Author

@asbjornu if that's ok, could you please approve it? Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants