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

Using this with react-native #46

Closed
somanysteves opened this issue Jan 8, 2019 · 3 comments
Closed

Using this with react-native #46

somanysteves opened this issue Jan 8, 2019 · 3 comments

Comments

@somanysteves
Copy link

I can see this library isn't exactly "production ready" - pretty sure it's not really meant for me to start using it yet, so I don't expect a whole lot of support - but I figured I'd ask :)

That said, I'm trying to get it going - and yes I know there is appcenter for react-native apis, but I really don't want to eject my expo app.

I've got it imported and I'm constructing the AppInsightsCore object. When I call .initialize though - it blows up on "no channels available".

it('AI', () => {
const ai = new AppInsightsCore();
let config2 = {
endpointUrl: "https://company.services.visualstudio.com/v2/track",
instrumentationKey: "my-instrumentation-key",
loglevelConsole:2,
loggingLevelTelemetry:2
};
ai.initialize(config2);

can't read property foreach of undefined.
So I made it happy with
ai.initialize(config2, [])
but that get's no channels available.

That's where I'm stuck at the moment.
The code seems clean and well written - I'm just not clear on exactly what channels are or where they come from.

I'd be happy to just get a hello world traced to my ai service though. So I was hoping there might be some extra docs/examples available to get a stub going.

@markwolff
Copy link

markwolff commented Jan 8, 2019

Hey @shortstevenn this is probably a fault of the README. This repo is meant to be only a dependency of the main repo (https://github.com/Microsoft/ApplicationInsights-JS/tree/master/AISKU#getting-started), and not directly used by itself. Perhaps it should just link there or copy the other readme altogether. Please try the Getting Started guide and open an issue in the main repo if you face the same problems!

npm i --save @microsoft/applicationinsights-web

import { ApplicationInsights } from '@microsoft/applicationinsights-web'
const appInsights = new ApplicationInsights({ config: {
  instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE',
  /* ...Other Configuration Options... */
}});
appInsights.loadAppInsights();

@somanysteves
Copy link
Author

@markwolff thanks. I saw that one (and the nodejs one too lol) but it's web specific so react-native gives all that "document is not defined" fun. Your library was core js so I was hopeful I could shim it in without the web dependencies. It seems like I'm close - I think I just need to write my own channel to the ai http posting api.

@markwolff
Copy link

markwolff commented Jan 8, 2019

@shortstevenn Actually we have something exactly for this scenario (specifically webworkers). You can use our "basic sku" which does not have any dependencies on the DOM. It comes with a channel builtin & ready to go. You will need to write a shim for all of the "tracks" you want to do, which it seems like you've already done. You just call track with your telemetry items and it sends it through the channel for you. Let me know how it works out for you.

https://github.com/Microsoft/ApplicationInsights-JS/tree/master/AISKU#application-insights-web-basic

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

No branches or pull requests

2 participants