1
0
Форкнуть 0
This commit is contained in:
Mark Wolff 2020-04-03 10:30:40 -07:00
Родитель 0f210df244
Коммит 5e8b33b485
29 изменённых файлов: 867 добавлений и 350 удалений

8
.eslintignore Normal file
Просмотреть файл

@ -0,0 +1,8 @@
# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
build
# don't lint nyc coverage output
coverage
# don't lint generated files
src/Declarations

24
.eslintrc.js Normal file
Просмотреть файл

@ -0,0 +1,24 @@
module.exports = {
settings: {
node: {
"resolvePaths": [__dirname],
"tryExtensions": [".ts"]
}
},
extends: [
'airbnb-typescript/base',
"plugin:node/recommended",
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
rules: {
'no-underscore-dangle': [ 'error', { allowAfterThis: true }],
'node/no-unsupported-features/es-syntax': ['error', { ignores: ['modules'] }],
'import/prefer-default-export': 'off',
},
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
sourceType: 'module'
},
};

353
.gitignore поставляемый
Просмотреть файл

@ -1,350 +1,3 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
node_modules
build
.npmrc

9
.prettierrc.json Normal file
Просмотреть файл

@ -0,0 +1,9 @@
{
"trailingComma": "all",
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"endOfLine": "lf",
"useTabs": false,
"printWidth": 110
}

7
.vscode/settings.json поставляемый Normal file
Просмотреть файл

@ -0,0 +1,7 @@
{
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"eslint.enable": true,
"eslint.alwaysShowStatus": true,
"files.eol": "\n"
}

42
package.json Normal file
Просмотреть файл

@ -0,0 +1,42 @@
{
"name": "opentelemetry-azure-monitor-js",
"version": "0.0.0",
"description": "Application Insights exporter for the Open Telemetry JavaScript (Node.js) SDK",
"main": "build/index.js",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint src --ext .ts",
"build": "tsc -p ./tsconfig.json"
},
"engines": {
"node": ">=8.3.0"
},
"author": "appinsightssdk@microsoft.com",
"license": "MIT",
"devDependencies": {
"@types/mocha": "^7.0.2",
"@types/node": "^13.9.8",
"@typescript-eslint/eslint-plugin": "^2.26.0",
"eslint": "^6.8.0",
"eslint-config-airbnb-typescript": "^7.2.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.2",
"husky": "^4.2.3",
"lerna": "^3.20.2",
"lerna-changelog": "^1.0.1",
"mocha": "^7.1.1",
"nyc": "^15.0.0",
"prettier": "^2.0.2",
"tslint": "^6.1.0",
"typescript": "^3.8.3"
},
"dependencies": {
"@opentelemetry/api": "^0.5.2",
"@opentelemetry/base": "^0.5.2",
"@opentelemetry/core": "^0.5.2",
"@opentelemetry/tracing": "^0.5.2"
}
}

Просмотреть файл

@ -0,0 +1,95 @@
export const DEFAULT_BREEZE_ENDPOINT = 'https://dc.services.visualstudio.com';
export const DEFAULT_LIVEMETRICS_ENDPOINT = 'https://rt.services.visualstudio.com';
export const DEFAULT_LIVEMETRICS_HOST = 'rt.services.visualstudio.com';
export enum QuickPulseCounter {
// Memory
COMMITTED_BYTES = '\\Memory\\Committed Bytes',
// CPU
PROCESSOR_TIME = '\\Processor(_Total)\\% Processor Time',
// Request
REQUEST_RATE = '\\ApplicationInsights\\Requests/Sec',
REQUEST_FAILURE_RATE = '\\ApplicationInsights\\Requests Failed/Sec',
REQUEST_DURATION = '\\ApplicationInsights\\Request Duration',
// Dependency
DEPENDENCY_RATE = '\\ApplicationInsights\\Dependency Calls/Sec',
DEPENDENCY_FAILURE_RATE = '\\ApplicationInsights\\Dependency Calls Failed/Sec',
DEPENDENCY_DURATION = '\\ApplicationInsights\\Dependency Call Duration',
// Exception
EXCEPTION_RATE = '\\ApplicationInsights\\Exceptions/Sec',
}
export enum PerformanceCounter {
// Memory
PRIVATE_BYTES = '\\Process(??APP_WIN32_PROC??)\\Private Bytes',
AVAILABLE_BYTES = '\\Memory\\Available Bytes',
// CPU
PROCESSOR_TIME = '\\Processor(_Total)\\% Processor Time',
PROCESS_TIME = '\\Process(??APP_WIN32_PROC??)\\% Processor Time',
// Requests
REQUEST_RATE = '\\ASP.NET Applications(??APP_W3SVC_PROC??)\\Requests/Sec',
REQUEST_DURATION = '\\ASP.NET Applications(??APP_W3SVC_PROC??)\\Request Execution Time',
}
/**
* Map a PerformanceCounter/QuickPulseCounter to a QuickPulseCounter. If no mapping exists, mapping is *undefined*
*/
export const PerformanceToQuickPulseCounter: { [key: string]: QuickPulseCounter } = {
[PerformanceCounter.PROCESSOR_TIME]: QuickPulseCounter.PROCESSOR_TIME,
[PerformanceCounter.REQUEST_RATE]: QuickPulseCounter.REQUEST_RATE,
[PerformanceCounter.REQUEST_DURATION]: QuickPulseCounter.REQUEST_DURATION,
// Remap quick pulse only counters
[QuickPulseCounter.COMMITTED_BYTES]: QuickPulseCounter.COMMITTED_BYTES,
[QuickPulseCounter.REQUEST_FAILURE_RATE]: QuickPulseCounter.REQUEST_FAILURE_RATE,
[QuickPulseCounter.DEPENDENCY_RATE]: QuickPulseCounter.DEPENDENCY_RATE,
[QuickPulseCounter.DEPENDENCY_FAILURE_RATE]: QuickPulseCounter.DEPENDENCY_FAILURE_RATE,
[QuickPulseCounter.DEPENDENCY_DURATION]: QuickPulseCounter.DEPENDENCY_DURATION,
[QuickPulseCounter.EXCEPTION_RATE]: QuickPulseCounter.EXCEPTION_RATE,
};
// Note: Explicitly define these types instead of using enum due to
// potential 'export enum' issues with typescript < 2.0.
export type QuickPulseDocumentType =
| 'Event'
| 'Exception'
| 'Trace'
| 'Metric'
| 'Request'
| 'RemoteDependency'
| 'Availability';
export type QuickPulseType =
| 'EventTelemetryDocument'
| 'ExceptionTelemetryDocument'
| 'TraceTelemetryDocument'
| 'MetricTelemetryDocument'
| 'RequestTelemetryDocument'
| 'DependencyTelemetryDocument'
| 'AvailabilityTelemetryDocument';
// OpenTelemetry Span Attributes
export const SpanAttribute = {
// HTTP
HttpHost: 'http.host',
HttpMethod: 'http.method',
HttpPort: 'http.port',
HttpStatusCode: 'http.status_code',
HttpUrl: 'http.url',
HttpUserAgent: 'http.user_agent',
// GRPC
GrpcMethod: 'grpc.method',
GrpcService: 'rpc.service', // rpc not grpc
};
export const DependencyTypeName = {
Grpc: 'GRPC',
Http: 'HTTP',
InProc: 'InProc',
};

Просмотреть файл

@ -0,0 +1,24 @@
/**
* Subset of Connection String fields which this SDK can parse. Lower-typecased to
* allow for case-insensitivity across field names
* @type ConnectionStringKey
*/
export interface ConnectionString {
authorization?: string;
instrumentationkey?: string;
ingestionendpoint?: string;
liveendpoint?: string;
location?: string;
endpointsuffix?: string;
// Note: this is a node types backcompat equivalent to
// type ConnectionString = { [key in ConnectionStringKey]?: string }
}
export type ConnectionStringKey =
| 'authorization'
| 'instrumentationkey'
| 'ingestionendpoint'
| 'liveendpoint'
| 'location'
| 'endpointsuffix';

Просмотреть файл

@ -0,0 +1,16 @@
// THIS FILE WAS AUTOGENERATED
/**
* Data struct to contain only C section with custom fields.
*/
class Base {
/**
* Name of item (B section) if any. If telemetry data is derived straight from this, this should be null.
*/
public baseType: string | undefined;
public properties: any;
constructor() {}
}
export = Base;

Просмотреть файл

@ -0,0 +1,153 @@
// THIS FILE WAS AUTOGENERATED
class ContextTagKeys {
/**
* Application version. Information in the application context fields is always about the application that is sending the telemetry.
*/
public applicationVersion: string;
/**
* Unique client device id. Computer name in most cases.
*/
public deviceId: string;
/**
* Device locale using <language>-<REGION> pattern, following RFC 5646. Example 'en-US'.
*/
public deviceLocale: string;
/**
* Model of the device the end user of the application is using. Used for client scenarios. If this field is empty then it is derived from the user agent.
*/
public deviceModel: string;
/**
* Client device OEM name taken from the browser.
*/
public deviceOEMName: string;
/**
* Operating system name and version of the device the end user of the application is using. If this field is empty then it is derived from the user agent. Example 'Windows 10 Pro 10.0.10586.0'
*/
public deviceOSVersion: string;
/**
* The type of the device the end user of the application is using. Used primarily to distinguish JavaScript telemetry from server side telemetry. Examples: 'PC', 'Phone', 'Browser'. 'PC' is the default value.
*/
public deviceType: string;
/**
* The IP address of the client device. IPv4 and IPv6 are supported. Information in the location context fields is always about the end user. When telemetry is sent from a service, the location context is about the user that initiated the operation in the service.
*/
public locationIp: string;
/**
* A unique identifier for the operation instance. The operation.id is created by either a request or a page view. All other telemetry sets this to the value for the containing request or page view. Operation.id is used for finding all the telemetry items for a specific operation instance.
*/
public operationId: string;
/**
* The name (group) of the operation. The operation.name is created by either a request or a page view. All other telemetry items set this to the value for the containing request or page view. Operation.name is used for finding all the telemetry items for a group of operations (i.e. 'GET Home/Index').
*/
public operationName: string;
/**
* The unique identifier of the telemetry item's immediate parent.
*/
public operationParentId: string;
/**
* Name of synthetic source. Some telemetry from the application may represent a synthetic traffic. It may be web crawler indexing the web site, site availability tests or traces from diagnostic libraries like Application Insights SDK itself.
*/
public operationSyntheticSource: string;
/**
* The correlation vector is a light weight vector clock which can be used to identify and order related events across clients and services.
*/
public operationCorrelationVector: string;
/**
* Session ID - the instance of the user's interaction with the app. Information in the session context fields is always about the end user. When telemetry is sent from a service, the session context is about the user that initiated the operation in the service.
*/
public sessionId: string;
/**
* Boolean value indicating whether the session identified by ai.session.id is first for the user or not.
*/
public sessionIsFirst: string;
/**
* In multi-tenant applications this is the account ID or name which the user is acting with. Examples may be subscription ID for Azure portal or blog name blogging platform.
*/
public userAccountId: string;
/**
* Anonymous user id. Represents the end user of the application. When telemetry is sent from a service, the user context is about the user that initiated the operation in the service.
*/
public userId: string;
/**
* Authenticated user id. The opposite of ai.user.id, this represents the user with a friendly name. Since it's PII information it is not collected by default by most SDKs.
*/
public userAuthUserId: string;
/**
* Name of the role the application is a part of. For Azure environment, this should be initialized with
* [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.Role.Name
* See more details here: https://dzone.com/articles/accessing-azure-role-0
* It is recommended that you initialize environment variable with this value during machine startup, and then set context field from environment variable
* appInsights.client.context.tags[appInsights.client.context.keys.cloudRole] = process.env.RoleName
*/
public cloudRole: string;
/**
* Name of the instance where the application is running. For Azure environment, this should be initialized with
* [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.Id
* See more details here: https://dzone.com/articles/accessing-azure-role-0
* It is recommended that you initialize environment variable with this value during machine startup, and then set context field from environment variable
* appInsights.client.context.tags[appInsights.client.context.keys.cloudRoleInstance] = process.env.RoleInstanceId
*/
public cloudRoleInstance: string;
/**
* SDK version. See https://github.com/Microsoft/ApplicationInsights-Home/blob/master/SDK-AUTHORING.md#sdk-version-specification for information.
*/
public internalSdkVersion: string;
/**
* Agent version. Used to indicate the version of StatusMonitor installed on the computer if it is used for data collection.
*/
public internalAgentVersion: string;
/**
* This is the node name used for billing purposes. Use it to override the standard detection of nodes.
*/
public internalNodeName: string;
constructor() {
this.applicationVersion = 'ai.application.ver';
this.deviceId = 'ai.device.id';
this.deviceLocale = 'ai.device.locale';
this.deviceModel = 'ai.device.model';
this.deviceOEMName = 'ai.device.oemName';
this.deviceOSVersion = 'ai.device.osVersion';
this.deviceType = 'ai.device.type';
this.locationIp = 'ai.location.ip';
this.operationId = 'ai.operation.id';
this.operationName = 'ai.operation.name';
this.operationParentId = 'ai.operation.parentId';
this.operationSyntheticSource = 'ai.operation.syntheticSource';
this.operationCorrelationVector = 'ai.operation.correlationVector';
this.sessionId = 'ai.session.id';
this.sessionIsFirst = 'ai.session.isFirst';
this.userAccountId = 'ai.user.accountId';
this.userId = 'ai.user.id';
this.userAuthUserId = 'ai.user.authUserId';
this.cloudRole = 'ai.cloud.role';
this.cloudRoleInstance = 'ai.cloud.roleInstance';
this.internalSdkVersion = 'ai.internal.sdkVersion';
this.internalAgentVersion = 'ai.internal.agentVersion';
this.internalNodeName = 'ai.internal.nodeName';
}
}
export = ContextTagKeys;

Просмотреть файл

@ -0,0 +1,23 @@
// THIS FILE WAS AUTOGENERATED
import Base = require('./Base');
'use strict';
/**
* Data struct to contain both B and C sections.
*/
class Data<TDomain> extends Base {
/**
* Name of item (B section) if any. If telemetry data is derived straight from this, this should be null.
*/
public baseType: string | undefined;
/**
* Container for data item (B section).
*/
public baseData: TDomain | undefined;
constructor() {
super();
}
}
export = Data;

Просмотреть файл

@ -0,0 +1,9 @@
// THIS FILE WAS AUTOGENERATED
/**
* The abstract common base of all domains.
*/
class Domain {
constructor() {}
}
export = Domain;

Просмотреть файл

@ -0,0 +1,55 @@
// THIS FILE WAS AUTOGENERATED
import Base = require('./Base');
'use strict';
/**
* System variables for a telemetry item.
*/
class Envelope {
/**
* Envelope version. For internal use only. By assigning this the default, it will not be serialized within the payload unless changed to a value other than #1.
*/
public ver: number;
/**
* Type name of telemetry data item.
*/
public name: string | undefined;
/**
* Event date time when telemetry item was created. This is the wall clock time on the client when the event was generated. There is no guarantee that the client's time is accurate. This field must be formatted in UTC ISO 8601 format, with a trailing 'Z' character, as described publicly on https://en.wikipedia.org/wiki/ISO_8601#UTC. Note: the number of decimal seconds digits provided are variable (and unspecified). Consumers should handle this, i.e. managed code consumers should not use format 'O' for parsing as it specifies a fixed length. Example: 2009-06-15T13:45:30.0000000Z.
*/
public time: string | undefined;
/**
* Sampling rate used in application. This telemetry item represents 1 / sampleRate actual telemetry items.
*/
public sampleRate: number;
/**
* Sequence field used to track absolute order of uploaded events.
*/
public seq: string | undefined;
/**
* The application's instrumentation key. The key is typically represented as a GUID, but there are cases when it is not a guid. No code should rely on iKey being a GUID. Instrumentation key is case insensitive.
*/
public iKey: string | undefined;
/**
* Key/value collection of context properties. See ContextTagKeys for information on available properties.
*/
public tags: any;
/**
* Telemetry data item.
*/
public data: Base | undefined;
constructor() {
this.ver = 1;
this.sampleRate = 100.0;
this.tags = {};
}
}
export = Envelope;

Просмотреть файл

@ -0,0 +1,75 @@
// THIS FILE WAS AUTOGENERATED
import Domain = require('./Domain');
'use strict';
/**
* An instance of Remote Dependency represents an interaction of the monitored component with a remote component/service like SQL or an HTTP endpoint.
*/
class RemoteDependencyData extends Domain {
baseType: 'RemoteDependencyData' = 'RemoteDependencyData';
/**
* Schema version
*/
public ver: number;
/**
* Name of the command initiated with this dependency call. Low cardinality value. Examples are stored procedure name and URL path template.
*/
public name: string | undefined;
/**
* Identifier of a dependency call instance. Used for correlation with the request telemetry item corresponding to this dependency call.
*/
public id: string | undefined;
/**
* Result code of a dependency call. Examples are SQL error code and HTTP status code.
*/
public resultCode: string | undefined;
/**
* Request duration in format: DD.HH:MM:SS.MMMMMM. Must be less than 1000 days.
*/
public duration: string | undefined;
/**
* Indication of successfull or unsuccessfull call.
*/
public success: boolean;
/**
* Command initiated by this dependency call. Examples are SQL statement and HTTP URL's with all query parameters.
*/
public data: string | undefined;
/**
* Target site of a dependency call. Examples are server name, host address.
*/
public target: string | undefined;
/**
* Dependency type name. Very low cardinality value for logical grouping of dependencies and interpretation of other fields like commandName and resultCode. Examples are SQL, Azure table, and HTTP.
*/
public type: string | undefined;
/**
* Collection of custom properties.
*/
public properties: any;
/**
* Collection of custom measurements.
*/
public measurements: any;
constructor() {
super();
this.ver = 2;
this.success = true;
this.properties = {};
this.measurements = {};
}
}
export = RemoteDependencyData;

Просмотреть файл

@ -0,0 +1,69 @@
// THIS FILE WAS AUTOGENERATED
import Domain = require('./Domain');
'use strict';
/**
* An instance of Request represents completion of an external request to the application to do work and contains a summary of that request execution and the results.
*/
class RequestData extends Domain {
baseType: 'RequestData' = 'RequestData';
/**
* Schema version
*/
public ver: number;
/**
* Identifier of a request call instance. Used for correlation between request and other telemetry items.
*/
public id: string | undefined;
/**
* Source of the request. Examples are the instrumentation key of the caller or the ip address of the caller.
*/
public source: string | undefined; // @todo
/**
* Name of the request. Represents code path taken to process request. Low cardinality value to allow better grouping of requests. For HTTP requests it represents the HTTP method and URL path template like 'GET /values/{id}'.
*/
public name: string | undefined;
/**
* Request duration in format: DD.HH:MM:SS.MMMMMM. Must be less than 1000 days.
*/
public duration: string | undefined;
/**
* Result of a request execution. HTTP status code for HTTP requests.
*/
public responseCode: string | undefined;
/**
* Indication of successfull or unsuccessfull call.
*/
public success: boolean | undefined;
/**
* Request URL with all query string parameters.
*/
public url: string | undefined;
/**
* Collection of custom properties.
*/
public properties: any;
/**
* Collection of custom measurements.
*/
public measurements: any;
constructor() {
super();
this.ver = 2;
this.properties = {};
this.measurements = {};
}
}
export = RequestData;

Просмотреть файл

@ -0,0 +1,9 @@
// THIS FILE WAS AUTOGENERATED
export import Base = require('./Base');
export import ContextTagKeys = require('./ContextTagKeys');
export import Data = require('./Data');
export import Domain = require('./Domain');
export import Envelope = require('./Envelope');
export import RemoteDependencyData = require('./RemoteDependencyData');
export import RequestData = require('./RequestData');

Просмотреть файл

@ -0,0 +1,2 @@
export * from './Constants';
export * from './Generated';

35
src/config.ts Normal file
Просмотреть файл

@ -0,0 +1,35 @@
import { Logger } from '@opentelemetry/api';
import * as http from 'http';
import * as https from 'https';
export interface ExporterConfig {
// Buffer
maxStorageSize: number; // number of envelopes
// Exporter
instrumentationKey?: string;
connectionString?: string;
// Channel
maxBatchSizeBeforeSend: number; // number of envelopes
batchSendIntervalMs: number;
batchSendRetryIntervalMs: number;
logger?: Logger;
// Sender
maxConsecutiveFailuresBeforeWarning: number;
endpointUrl: string;
proxyHttpsUrl?: string;
proxyHttpUrl?: string;
httpAgent?: http.Agent;
httpsAgent?: https.Agent;
}
export const DEFAULT_EXPORTER_CONFIG: ExporterConfig = {
maxStorageSize: 2_000,
endpointUrl: 'https://dc.services.visualstudio.com/v2/track',
maxBatchSizeBeforeSend: 500,
batchSendIntervalMs: 15_000,
batchSendRetryIntervalMs: 60_000,
maxConsecutiveFailuresBeforeWarning: 10,
};

73
src/exporter.ts Normal file
Просмотреть файл

@ -0,0 +1,73 @@
import { ExportResult } from '@opentelemetry/base';
import { Logger } from '@opentelemetry/api';
import { NoopLogger } from '@opentelemetry/core';
import { Envelope } from './Declarations/Contracts';
import { AzureMonitorSender } from './platform';
import { ExporterConfig, DEFAULT_EXPORTER_CONFIG } from './config';
import { BaseExporter, TelemetryProcessor } from './types';
export abstract class AzureMonitorBaseExporter implements BaseExporter {
protected readonly _logger: Logger;
private readonly _sender: AzureMonitorSender;
private _telemetryProcessors: TelemetryProcessor[];
constructor(options: ExporterConfig = DEFAULT_EXPORTER_CONFIG) {
this._logger = options.logger || new NoopLogger();
// Instrumentation key is required
// @todo: parse connection strings
if (!options.instrumentationKey) {
this._logger.error('No instrumentation key was provided to the Azure Monitor Exporter');
}
this._telemetryProcessors = [];
this._sender = new AzureMonitorSender();
}
exportEnvelopes(payload: Envelope[], resultCallback: (result: ExportResult) => void): void {
const envelopes = this._applyTelemetryProcessors(payload);
this._sender.send(envelopes, (err, exportResult, result) => {
if (err) {
this._logger.error(err.message);
} else if (result) {
this._logger.info(result);
}
resultCallback(exportResult);
});
}
addTelemetryProcessor(processor: TelemetryProcessor): void {
this._telemetryProcessors.push(processor);
}
clearTelemetryProcessors() {
this._telemetryProcessors = [];
}
shutdown() {
this._sender.shutdown();
}
private _applyTelemetryProcessors(envelopes: Envelope[]): Envelope[] {
const filteredEnvelopes: Envelope[] = [];
envelopes.forEach((envelope) => {
let accepted = true;
this._telemetryProcessors.forEach((processor) => {
// Don't use CPU cycles if item is already rejected
if (accepted && processor(envelope) === false) {
accepted = false;
}
});
if (accepted) {
filteredEnvelopes.push(envelope);
}
});
return filteredEnvelopes;
}
}

1
src/index.ts Normal file
Просмотреть файл

@ -0,0 +1 @@
export * from './trace';

4
src/platform/index.ts Normal file
Просмотреть файл

@ -0,0 +1,4 @@
// Use the node platform by default. The "browser" field of package.json is used
// to override this file to use `./browser/index.ts` when packaged with
// webpack, Rollup, etc.
export * from './nodejs';

Просмотреть файл

@ -0,0 +1,14 @@
import { PersistentStorage } from '../../types';
export class ArrayPersist<T> implements PersistentStorage {
private _buffer: T[] = [];
shift(cb: (err: Error | null, value?: T) => void): void {
cb(null, this._buffer.shift());
}
push(value: T, cb: (err: Error | null, result?: boolean | undefined) => void): void {
this._buffer.push(value);
cb(null, true);
}
}

Просмотреть файл

@ -0,0 +1,5 @@
export const SDK_INFO = {
NAME: 'opentelemetry',
RUNTIME: 'node',
LANGUAGE: 'nodejs',
};

Просмотреть файл

@ -0,0 +1,6 @@
/**
* Node.js specific platform utils
*/
export * from './constants';
export * from './sender';
export * from './noopSender';

Просмотреть файл

@ -0,0 +1,22 @@
import { NoopLogger } from '@opentelemetry/core';
import { Logger } from '@opentelemetry/api';
import { ExportResult } from '@opentelemetry/base';
import { Sender, SenderCallback } from '../../types';
import { Envelope } from '../../Declarations/Contracts';
export class NoopSender implements Sender {
private readonly _logger: Logger;
constructor() {
this._logger = new NoopLogger();
}
send(payload: Envelope[], callback: SenderCallback): void {
this._logger.info('Sending payload', payload);
callback(null, ExportResult.SUCCESS);
}
shutdown(): void {
this._logger.info('Noop Sender shutting down');
}
}

22
src/trace.ts Normal file
Просмотреть файл

@ -0,0 +1,22 @@
import { ExportResult } from '@opentelemetry/base';
import { ReadableSpan, SpanExporter } from '@opentelemetry/tracing';
import { ExporterConfig, DEFAULT_EXPORTER_CONFIG } from './config';
import { readableSpanToEnvelope } from './utils/noopSpanUtils';
import { AzureMonitorBaseExporter } from './exporter';
export class AzureMonitorTraceExporter extends AzureMonitorBaseExporter implements SpanExporter {
constructor(options: ExporterConfig = DEFAULT_EXPORTER_CONFIG) {
super(options);
}
export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void {
this._logger.info('Exporting spans', spans);
const envelopes = spans.map((span) => readableSpanToEnvelope(span, '', this._logger));
this.exportEnvelopes(envelopes, resultCallback);
}
shutdown(): void {
this._logger.info('Azure Monitor Trace Exporter shutting down');
super.shutdown();
}
}

23
src/types.ts Normal file
Просмотреть файл

@ -0,0 +1,23 @@
import { ExportResult } from '@opentelemetry/base';
import { Envelope } from './Declarations/Contracts';
export type Tags = { [key: string]: string };
export type Properties = { [key: string]: string };
export type TelemetryProcessor = (envelope: Envelope) => boolean | void;
export type SenderCallback = (err: Error | null, exportResult: ExportResult, result?: string) => void;
export interface BaseExporter {
addTelemetryProcessor(processor: TelemetryProcessor): void;
clearTelemetryProcessors(): void;
exportEnvelopes(envelopes: Envelope[], resultCallback: (result: ExportResult) => void): void;
}
export interface Sender {
send(payload: unknown[], callback: SenderCallback): void;
shutdown(): void;
}
export interface PersistentStorage {
shift(cb: (err: Error | null, value?: unknown) => void): void;
push(value: unknown, cb: (err: Error | null, result?: boolean) => void): void;
}

Просмотреть файл

@ -0,0 +1,15 @@
import { ReadableSpan } from '@opentelemetry/tracing';
import { Logger } from '@opentelemetry/api';
import { Envelope } from '../Declarations/Contracts';
export function readableSpanToEnvelope(
span: ReadableSpan,
instrumentationKey: string,
logger?: Logger,
): Envelope {
if (logger) {
logger.info('Noop: Reshaping span', span, instrumentationKey);
}
return new Envelope();
}

24
tsconfig.json Normal file
Просмотреть файл

@ -0,0 +1,24 @@
{
"compilerOptions": {
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"declaration": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"pretty": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": true,
"target": "es2015",
"incremental": true,
"outDir": "build",
},
"include": [
"src/**/*.ts",
"test/**/*.ts"
]
}