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

[Master] Add local storage-based implementation #1419 #2037

Merged
merged 3 commits into from
Apr 11, 2023

Conversation

peitschie
Copy link
Contributor

@peitschie peitschie commented Apr 6, 2023

I'm aiming for the smallest diff with this to allow local storage.

This can be used like:

UPDATED

const appInsights = new ApplicationInsights({
  config: {
    enableSessionStorageBuffer: true,
    bufferOverride: { 
      getItem: (logger, key) => localStorage.getItem(key),
      setItem: (logger, key, value) => localStorage.setItem(key, value),
    }
  }
});

I wasn't sure if I should expose this on config just yet (e.g., enableLocalStorageBuffer). Ideally this eventually becomes a pluggable component, so that a hypothetical IndexedDb or completely custom storage mechanism can be inserted trivially. I thought about adding a simple factory method to IConfig, but the ISendBuffer interface is not available to that package currently.

Open to any feedback on this, including rejection if it's not taking this mechanism in a direction you're comfortable with.

Longer term, I'm starting to poke at how to nicely make the ISendBuffer async to allow more flexible storage mechanisms to be built, but enabling local storage seemed a very useful first step regardless.

@peitschie
Copy link
Contributor Author

I've pushed a full rewrite of this PR @MSNev. Once you're happy with the prod code, I'll add some tests proving the configuration options all behave nicely 🙂

I can appreciate major releases are many moving parts, so am happy to keep tweaking this until it fits nicely into your release plans!

@peitschie peitschie force-pushed the simple-local-storage branch 3 times, most recently from 952a894 to d92af76 Compare April 7, 2023 01:23
…osoft#1419

This can be used like:

```
const appInsights = new ApplicationInsights({
  config: {
    enableSessionStorageBuffer: true,
    bufferOverride: {
      getItem: (logger, key) => localStorage.getItem(key),
      setItem: (logger, key, value) => localStorage.setItem(key, value),
    }
  }
});
```
@peitschie
Copy link
Contributor Author

I've added tests exercising the new config paths now.

_self._buffer = (_self._senderConfig.enableSessionStorageBuffer() && utlCanUseSessionStorage())
? new SessionStorageSendBuffer(diagLog, _self._senderConfig) : new ArraySendBuffer(diagLog, _self._senderConfig);
const useSessionStorage = _self._senderConfig.enableSessionStorageBuffer() &&
(_self._senderConfig.bufferOverride() || utlCanUseSessionStorage())

Check notice

Code scanning / CodeQL

Semicolon insertion

Avoid automated semicolon insertion (96% of all statements in [the enclosing function](1) have an explicit semicolon).
@MSNev MSNev changed the title Add local storage-based implementation #1419 [Master] Add local storage-based implementation #1419 Apr 11, 2023
@MSNev MSNev added this to the 2.8.12 milestone Apr 11, 2023
@MSNev MSNev merged commit c14a47f into microsoft:master Apr 11, 2023
MSNev added a commit that referenced this pull request Apr 11, 2023
#2037)

This can be used like:

```
const appInsights = new ApplicationInsights({
  config: {
    enableSessionStorageBuffer: true,
    bufferOverride: {
      getItem: (logger, key) => localStorage.getItem(key),
      setItem: (logger, key, value) => localStorage.setItem(key, value),
    }
  }
});
```

Co-authored-by: Nev <54870357+MSNev@users.noreply.github.com>
MSNev added a commit that referenced this pull request Apr 12, 2023
* [BUG] The documentation for enableDebug is incorrect, it should reference enableDebugExceptions #2014 (#2022)

* [BUG] SDK LOAD Failure reporting not working #2027 (#2038)

* Add a simple interface to enable custom buffer storage solutions #1419 (#2037)

This can be used like:

```
const appInsights = new ApplicationInsights({
  config: {
    enableSessionStorageBuffer: true,
    bufferOverride: {
      getItem: (logger, key) => localStorage.getItem(key),
      setItem: (logger, key, value) => localStorage.setItem(key, value),
    }
  }
});
```

Co-authored-by: Nev <54870357+MSNev@users.noreply.github.com>

* [Master] Add readme documentation for IStorageBuffer (#2045)

* [Release] Increase version to 2.8.12 (#2046)

---------

Co-authored-by: Philip Peitsch <philip.peitsch@gmail.com>
@peitschie peitschie deleted the simple-local-storage branch April 19, 2023 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants