Code Monkey home page Code Monkey logo

hyperdx-otel-react-native's Introduction

Splunk Distribution of OpenTelemetry for React Native

🚧 Splunk React Native instrumentation distribution is currently in BETA. By using this package in production-grade environments, users accept all limitations of beta maturity software, including the possibility of breaking changes introduced in any release. Limited support will be provided to active Splunk Observability Cloud customers.

Overview

This library lets you autoinstrument React Native applications. Minimum supported React Native version is 0.68. To instrument applications running on React Native versions lower than 0.68, see Instrument lower versions.

Get started

To instrument your React Native application, follow these steps.

  1. Install the library using either npm or yarn:
# npm
npm install @splunk/otel-react-native

# yarn
yarn add @splunk/otel-react-native
  1. Initialize the library as early in your app lifecycle as possible:
import { SplunkRum } from '@splunk/otel-react-native';

const Rum = SplunkRum.init({
  realm: 'us0',
  applicationName: 'reactNativeTest',
  rumAccessToken: 'token',
});
  1. Customize the initialization parameters to specify:
  • realm: The Splunk Observability Cloud realm of your organization. For example, us0.
  • rumAccessToken: Your Splunk RUM authentication token. You can find or generate the token here. Notice that RUM and APM authentication tokens are different.
  • applicationName: Name of your application. Set it to distinguish your app from others in Splunk Observability Cloud.

If needed, you can set a different target URL by specifying a value for beaconEndpoint. Setting a different beacon URL overrides the realm setting.

Instrument lower versions

To instrument applications running on React Native versions lower than 0.68, edit your metro.config.js file to force metro to use browser specific packages. For example:

const defaultResolver = require('metro-resolver');

module.exports = {
  resolver: {
    resolveRequest: (context, realModuleName, platform, moduleName) => {
      const resolved = defaultResolver.resolve(
        {
          ...context,
          resolveRequest: null,
        },
        moduleName,
        platform,
      );

      if (
        resolved.type === 'sourceFile' &&
        resolved.filePath.includes('@opentelemetry')
      ) {
        resolved.filePath = resolved.filePath.replace(
          'platform\\node',
          'platform\\browser',
        );
        return resolved;
      }

      return resolved;
    },
  },
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: true,
      },
    }),
  },
};

View navigation

react-navigation version 5 and 6 are supported.

The following example shows how to instrument navigation:

import { startNavigationTracking } from '@splunk/otel-react-native';

export default function App() {
  const navigationRef = useNavigationContainerRef();
  return (
    <NavigationContainer
      ref={navigationRef}
      onReady={() => {
        startNavigationTracking(navigationRef);
      }}
    >
      <Stack.Navigator>
        ...
      </Stack.Navigator>
    </NavigationContainer>
  );
}

Data collection

The library exports data using the Zipkin exporter. Adding your own exporters and processors isn't supported yet.

Supported features:

  • Autoinstrumented HTTP requests
  • Autoinstrumented JS Error tracking
  • Autoinstrumented navigation tracking for react-navigation
  • Session tracking
  • Custom instrumentation using Opentelemetry
  • Capturing native crashes

For more information about how this library uses Opentelemetry and about future plans check CONTRIBUTING.md.

License

Copyright 2023 Splunk Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

ℹ️  SignalFx was acquired by Splunk in October 2019. See Splunk SignalFx for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.