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

Add apiKey as a mutable property of BugsnagEvent #458

Merged

Conversation

robinmacharg
Copy link
Contributor

@robinmacharg robinmacharg commented Feb 6, 2020

Goal

Add an apiKey property to BugsnagEvent (nee BugsnagCrashReport). The behaviour is:

  • Library consumers should be able to change the API key of event from OnError callbacks
  • The property defaults to the value from BugsnagConfiguration.apiKey.
  • Changing this value should change the API key used in the payload body and header but not the global Configuration value.

Design

A simple @property with custom getter/setter logic and validation. The BugsnagConfiguration.isValidApiKey method was promoted to class-level since it's now used in two places.

Failing validation logs the failure but doesn't throw an error. The thinking is that there will always be a fallback valid (32 digit hex string) apiKey and so event capture is the priority.

Changeset

Just BugsnagEvent.m/h and associated unit tests.

Tests

Tested that:

  • The value retrieved the Configuration value when unset.
  • A new value could be set in the event callback and this did not change the global value.
  • The validation failure behaviour is correct.

Did not add any testing that the overridden apiKey value is correctly being sent to the backend via HTTP headers although this was observed in informal testing. A solution to this involving swizzling the ApiClient class was examined but deemed unnecessarily complex.

Review

Outstanding Questions

  • This pull request is ready for:
    • Initial review of the intended approach, not yet feature complete
    • Structural review of the classes, functions, and properties modified
    • Final review
  • The correct target branch has been selected (master for fixes, next for
    features)
  • Consistency across platforms for structures or concepts added or modified
  • Consistency between the changeset and the goal stated above
  • Internal consistency with the rest of the library - is there any overlap between existing interfaces and any which have been added?
  • Usage friction - is the proposed change in usage cumbersome or complicated?
  • Performance and complexity - are there any cases of unexpected O(n^3) when iterating, recursing, flat mapping, etc?
  • Concurrency concerns - if components are accessed asynchronously, what issues will arise
  • Thoroughness of added tests and any missing edge cases
  • Idiomatic use of the language

@robinmacharg robinmacharg force-pushed the robinmacharg/Add-apiKey-as-a-mutable-property branch from f56a790 to dcec383 Compare February 6, 2020 15:30
@robinmacharg robinmacharg force-pushed the robinmacharg/Add-apiKey-as-a-mutable-property branch 2 times, most recently from f2e03c5 to 8436791 Compare February 7, 2020 10:10
@robinmacharg robinmacharg changed the base branch from master to spec-compliance February 7, 2020 15:45
@robinmacharg robinmacharg marked this pull request as ready for review February 7, 2020 15:49
@robinmacharg robinmacharg changed the title Robinmacharg/add api key as a mutable property Add apiKey as a mutable property of BugsnagEvent Feb 7, 2020
Copy link
Contributor

@fractalwrench fractalwrench left a comment

Choose a reason for hiding this comment

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

I left a couple of minor comments but otherwise this change LGTM. Happy for it to be merged once the tests are passing and comments resolved 👍

CHANGELOG.md Outdated Show resolved Hide resolved
Tests/BugsnagEventTests.m Outdated Show resolved Hide resolved
Source/BugsnagConfiguration.h Outdated Show resolved Hide resolved
@robinmacharg robinmacharg force-pushed the robinmacharg/Add-apiKey-as-a-mutable-property branch from 8436791 to 0400c6e Compare February 10, 2020 11:44
@robinmacharg robinmacharg merged commit d477010 into spec-compliance Feb 10, 2020
@robinmacharg robinmacharg deleted the robinmacharg/Add-apiKey-as-a-mutable-property branch February 10, 2020 13:39
robinmacharg added a commit that referenced this pull request Feb 12, 2020
* refactor: rename BugsnagCrashReport to BugsnagEvent
* feat: add per-BugsnagEvent mutable apiKey
robinmacharg added a commit that referenced this pull request Feb 14, 2020
* refactor: rename BugsnagCrashReport to BugsnagEvent
* feat: add per-BugsnagEvent mutable apiKey
robinmacharg added a commit that referenced this pull request Feb 18, 2020
* refactor: rename BugsnagCrashReport to BugsnagEvent
* feat: add per-BugsnagEvent mutable apiKey
robinmacharg added a commit that referenced this pull request Feb 18, 2020
* refactor: rename BugsnagCrashReport to BugsnagEvent
* feat: add per-BugsnagEvent mutable apiKey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants