npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-amp-diagnostics-logger

v1.8.0

Published

ng-amp-diagnostics-logger is a package that sends Azure Media Player telemetry information to Azure Application Insights in a Angular application

Downloads

44

Readme

About ng-amp-diagnostics-logger

ng-amp-diagnostics-logger is a package that sends Azure Media Player telemetry information to Azure Application Insights in a Angular application. ng-amp-diagnostics-logger is a TypeScript conversion of the amp-diagnosticsLogger.js JavaScript library.

Install

npm i ng-amp-diagnostics-logger --save-dev

Sample Code

  <!--HEAD tag of index.html-->
  <link href="//amp.azure.net/libs/amp/latest/skins/amp-default/azuremediaplayer.min.css" rel="stylesheet">
  <script src="//amp.azure.net/libs/amp/latest/azuremediaplayer.min.js"></script>   
/**
 * app.component.ts
*/

//import
import { NgAmpDiagnosticsLoggerService, NgAmpDiagnosticsLoggerConfiguration } from 'ng-amp-diagnostics-logger'

// constructor
 constructor(private ngAmpDiagnosticsLoggerService: NgAmpDiagnosticsLoggerService) { }

 // ngAfterViewInit
const ngAmpDiagnosticsLoggerConfiguration: NgAmpDiagnosticsLoggerConfiguration =  {
    appName: 'some-component',
    player: this.player,
    instrumentationKey: 'APPLICATION INSIGHTS INSTRUMENTATION KEY HERE'};
    this.ngAmpDiagnosticsLoggerService.initialize(ngAmpDiagnosticsLoggerConfiguration); 
    }

// when media is played in the component
// some unqiue string will be stored in Application Insights User Id field
this.ngAmpDiagnosticsLoggerService.log('SOME UNIQUE STRING');    

Full sample and documentation can be found here

NgAmpDiagnosticsLoggerService Dependencies:

Components

NgAmpDiagnosticsLoggerConfiguration - This interface is used to initialize the NgAmpDiagnosticsLoggerService Service when a Angular Component is ready to use the service. The interface has 3 properties:

  • appName - The name of the application that is using the NgAmpDiagnosticsLoggerService service. This can be set to any value.
  • instrumentationKey - The Application Insights Instrumentation Key used by applicationinsights-js
  • player - The azuremediaplayer.d.ts player object

NgAmpDiagnosticsLoggerService - This service is a custom TypeScript service and is a conversion of the amp-diagnosticsLogger.js JavaScript library to TypeScript as there wasn't any TypeScript libraries to use at this time.

The service has 2 public methods:

  • initialize Method - This method accepts a NgAmpDiagnosticsLoggerConfiguration object and initializes the NgAmpDiagnosticsLoggerService service by setting important private variables. This method also sets the callback variable, which is used to log telemetry data to Application Insights.
  • log Method - This method accepts a string to serve as the value for the Application Insights User Id field. At the time this documentation was written, we are using the ProjectId field from the Project Table. This method evaluates the _isInitalized and _isConfigured private variables to determine if plumbing to wireup the Azure Media Player events to send telemetry data to Application Insights.

If _isInitialized is false, the service will log a warning to the JavaScript console. If _isConfigured is false, the method will:

  • Execute the code to add a TelemetryInitializer to the applicationinsights-js node package AppInsights object context. The TelemetryInializer is used to set the Application Insights User Id field via the ['ai.user.id'] tag.
  • Execute the code to wireup the Azure Media Player events to send telemetry data to Application Insights. At the time this documentation was written, all Azure Media Player events are being logged to Application insights.

Possible Improvements

  • Mocking - In the future, it would be beneficial inject the amp and AppInsights object into the NgAmpDiagnosticsLoggerService service. The amp object is just a namespace, so I was not able to figure out how to inject this object. I was able to inject the AppInsights object into the constructor but I observed very odd and inconsistent behavior when not just using this object directly. Injecting these objects into the constructor will allow for the service to be tested via mocking.
  • Custom Callback - In the future, it may be beneficial to make the callback variable a property in the NgAmpDiagnosticsLoggerService interface to allow for custom code for logging.
  • Configurable Console Logging - In the future, it may be benefical to add a new property to the AmpDiagnosticsLoggerConfiguration interface that can be used to turn on/off console logging in the NgAmpDiagnosticsLoggerService Service.
  • Configure Events - In the future, it may be beneficial to make configurable which Azure Media Player Events are sent to Application Insights.
  • Set Multiple Application Insights Fields - In the future, it would be beneficial to be able to set more than just the Application Insights User Id field.

External Resources

How to send Azure Media Player Telemetry Information to Azure Application Insights in a Angular 7 Application

License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT License.