Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: microsoft/ApplicationInsights-node.js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.1.8
Choose a base ref
...
head repository: microsoft/ApplicationInsights-node.js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2.1.9
Choose a head ref
  • 15 commits
  • 40 files changed
  • 4 contributors

Commits on Oct 20, 2021

  1. SDK prevents app crash in Linux Azure App Services (#854)

    * SDK prevents app crash in Linux Azure App Services
    
    * Tests
    hectorhdzg authored Oct 20, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fb67ee7 View commit details

Commits on Oct 21, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c8f5f51 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    66bdc31 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2584172 View commit details
  4. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    06e25bf View commit details

Commits on Oct 25, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a4a994f View commit details

Commits on Oct 26, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ebb35e0 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    577354c View commit details

Commits on Oct 27, 2021

  1. Respect existing trace headers when using Azure Function contexts (#817)

    Co-authored-by: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com>
    f0o and hectorhdzg authored Oct 27, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5d5e8ee View commit details

Commits on Oct 28, 2021

  1. feat: use @azure/logger (#801)

    * feat: use @azure/logger
    
    * fix tests
    
    * add tags
    
    * fix build
    
    * update
    
    * address comments
    
    * revert error and debug method
    
    Co-authored-by: Jeff Mealo <jeff.m@jarv.us>
    Co-authored-by: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com>
    3 people authored Oct 28, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1e5ef31 View commit details
  2. Generate correlation context for dependencies with no request associa…

    …ted (#861)
    
    * Generate correlation context for dependencies with no request associated
    
    * Test
    hectorhdzg authored Oct 28, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9aaf960 View commit details

Commits on Oct 29, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b4fccad View commit details

Commits on Nov 8, 2021

  1. Handle JSON stringify errors (#867)

    * Handle JSON stringify errors
    
    * Statsbeat test reliability
    
    * Update
    
    * Add error handling to get more accurate error in tests
    
    * Update
    
    * Using promises instead of callbacks
    Remove interval check as it makes test unreliable
    hectorhdzg authored Nov 8, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f4e1bc4 View commit details

Commits on Nov 11, 2021

  1. Allowing internal logs to be stored in local file (#866)

    * Statsbeat update function resource provider
    
    * WIP
    
    * Allowing internal logs to be stored in local file
    
    * Adding cleanup in tests
    
    * Async refactor
    hectorhdzg authored Nov 11, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9b5f3b6 View commit details
  2. 2.1.9 release (#868)

    hectorhdzg authored Nov 11, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    dca4088 View commit details
Showing with 1,343 additions and 783 deletions.
  1. +1 −0 .gitignore
  2. +18 −2 AutoCollection/CorrelationContextManager.ts
  3. +0 −1 AutoCollection/Exceptions.ts
  4. +21 −2 AutoCollection/HttpDependencies.ts
  5. +38 −24 AutoCollection/HttpDependencyParser.ts
  6. +31 −6 AutoCollection/HttpRequestParser.ts
  7. +76 −72 AutoCollection/Statsbeat.ts
  8. +5 −2 AutoCollection/diagnostic-channel/SpanParser.ts
  9. +4 −0 AutoCollection/diagnostic-channel/azure-coretracing.sub.ts
  10. +15 −6 AutoCollection/diagnostic-channel/bunyan.sub.ts
  11. +4 −0 AutoCollection/diagnostic-channel/console.sub.ts
  12. +4 −0 AutoCollection/diagnostic-channel/mongodb.sub.ts
  13. +4 −0 AutoCollection/diagnostic-channel/mysql.sub.ts
  14. +4 −0 AutoCollection/diagnostic-channel/postgres.sub.ts
  15. +4 −0 AutoCollection/diagnostic-channel/redis.sub.ts
  16. +4 −0 AutoCollection/diagnostic-channel/winston.sub.ts
  17. +2 −12 Bootstrap/StatusLogger.ts
  18. +1 −1 Declarations/Constants.ts
  19. +1 −1 Library/AzureVirtualMachine.ts
  20. +4 −4 Library/Channel.ts
  21. +28 −17 Library/CorrelationIdManager.ts
  22. +164 −0 Library/FileAccessControl.ts
  23. +76 −0 Library/FileSystemHelper.ts
  24. +159 −0 Library/InternalAzureLogger.ts
  25. +7 −6 Library/Logging.ts
  26. +1 −1 Library/QuickPulseSender.ts
  27. +94 −328 Library/Sender.ts
  28. +1 −1 Library/TelemetryClient.ts
  29. +83 −43 Library/Util.ts
  30. +54 −5 Tests/AutoCollection/HttpDependencies.tests.ts
  31. +130 −148 Tests/AutoCollection/Statsbeat.tests.ts
  32. +6 −3 Tests/AutoCollection/bunyan.tests.ts
  33. +77 −54 Tests/EndToEnd.tests.ts
  34. +2 −1 Tests/Library/Channel.tests.ts
  35. +114 −0 Tests/Library/InternalAzureLogger.tests.ts
  36. +75 −15 Tests/Library/Logging.tests.ts
  37. +9 −7 Tests/Library/Sender.tests.ts
  38. +4 −4 Tests/Library/Util.tests.ts
  39. +14 −14 package-lock.json
  40. +4 −3 package.json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -31,3 +31,4 @@ Tests/FunctionalTests/TestApp/package-lock.json

# Ignore log files
npm-debug.log
undefined/temp/appInsights-node/applicationinsights.log
20 changes: 18 additions & 2 deletions AutoCollection/CorrelationContextManager.ts
Original file line number Diff line number Diff line change
@@ -197,8 +197,24 @@ export class CorrelationContextManager {

// AzFunction TraceContext available
if (traceContext) {
const traceparent = new Traceparent(traceContext.traceparent);
const tracestate = new Tracestate(traceContext.tracestate);
let traceparent = null;
let tracestate = null;
if ( (request as azureFunctionsTypes.HttpRequest).headers ) {
if( (request as azureFunctionsTypes.HttpRequest).headers.traceparent ) {
traceparent = new Traceparent((request as azureFunctionsTypes.HttpRequest).headers.traceparent);
} else if ( (request as azureFunctionsTypes.HttpRequest).headers["request-id"] ) {
traceparent = new Traceparent(null, (request as azureFunctionsTypes.HttpRequest).headers["request-id"]);
}
if( (request as azureFunctionsTypes.HttpRequest).headers.tracestate ) {
tracestate = new Tracestate((request as azureFunctionsTypes.HttpRequest).headers.tracestate);
}
}
if( !traceparent ) {
traceparent = new Traceparent(traceContext.traceparent);
}
if( !tracestate ) {
tracestate = new Tracestate(traceContext.tracestate);
}
const parser = typeof request === "object"
? new HttpRequestParser(request)
: null;
1 change: 0 additions & 1 deletion AutoCollection/Exceptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import http = require("http");

import Contracts = require("../Declarations/Contracts");
import Logging = require("../Library/Logging");
import TelemetryClient = require("../Library/TelemetryClient");
import Sender = require("../Library/Sender");
import Queue = require("../Library/Channel");
23 changes: 21 additions & 2 deletions AutoCollection/HttpDependencies.ts
Original file line number Diff line number Diff line change
@@ -72,7 +72,26 @@ class AutoCollectHttpDependencies {

if (request && options && shouldCollect) {
CorrelationContextManager.wrapEmitter(request);
AutoCollectHttpDependencies.trackRequest(this._client, { options: options, request: request });
// If there is no context create one, this apply when no request is triggering the dependency
if (!CorrelationContextManager.getCurrentContext()) {
// Create correlation context and wrap execution
let operationId = null;
if (CorrelationIdManager.w3cEnabled) {
let traceparent = new Traceparent();
operationId = traceparent.traceId;
}
else {
let requestId = CorrelationIdManager.generateRequestId(null);
operationId = CorrelationIdManager.getRootId(requestId);
}
let correlationContext = CorrelationContextManager.generateContextObject(operationId);
CorrelationContextManager.runWithContext(correlationContext, () => {
AutoCollectHttpDependencies.trackRequest(this._client, { options: options, request: request });
});
}
else {
AutoCollectHttpDependencies.trackRequest(this._client, { options: options, request: request });
}
}
};

@@ -169,7 +188,7 @@ class AutoCollectHttpDependencies {
if (currentContext.operation.tracestate) {
const tracestate = currentContext.operation.tracestate.toString();
if (tracestate) {
telemetry.request.setHeader(RequestResponseHeaders.traceStateHeader, tracestate)
telemetry.request.setHeader(RequestResponseHeaders.traceStateHeader, tracestate);
}
}

62 changes: 38 additions & 24 deletions AutoCollection/HttpDependencyParser.ts
Original file line number Diff line number Diff line change
@@ -43,20 +43,22 @@ class HttpDependencyParser extends RequestParser {
* Gets a dependency data contract object for a completed ClientRequest.
*/
public getDependencyTelemetry(baseTelemetry?: Contracts.Telemetry, dependencyId?: string): Contracts.DependencyTelemetry {
let urlObject = new url.URL(this.url);
urlObject.search = undefined;
urlObject.hash = undefined;
let dependencyName = this.method.toUpperCase() + " " + urlObject.pathname;


let dependencyName = this.method.toUpperCase();
let remoteDependencyType = Contracts.RemoteDependencyDataConstants.TYPE_HTTP;
let remoteDependencyTarget = "";
try {
let urlObject = new url.URL(this.url);
urlObject.search = undefined;
urlObject.hash = undefined;
dependencyName += " " + urlObject.pathname;
remoteDependencyTarget = urlObject.hostname;
if (urlObject.port) {
remoteDependencyTarget += ":" + urlObject.port;
}

let remoteDependencyTarget = urlObject.hostname;

if (urlObject.port) {
remoteDependencyTarget += ":" + urlObject.port;
}

catch (ex) { // Invalid URL
}
if (this.correlationId) {
remoteDependencyType = Contracts.RemoteDependencyDataConstants.TYPE_AI;
if (this.correlationId !== CorrelationIdManager.correlationIdPrefix) {
@@ -113,15 +115,21 @@ class HttpDependencyParser extends RequestParser {
if (typeof options === 'string') {
if (options.indexOf("http://") === 0 || options.indexOf("https://") === 0) {
// protocol exists, parse normally
options = new url.URL(options);
try {
options = new url.URL(options);
}
catch (ex) { }
} else {
// protocol not found, insert http/https where appropriate
const parsed = new url.URL("http://" + options);
if (parsed.port === "443") {
options = new url.URL("https://" + options);
} else {
options = new url.URL("http://" + options);
try {
const parsed = new url.URL("http://" + options);
if (parsed.port === "443") {
options = new url.URL("https://" + options);
} else {
options = new url.URL("http://" + options);
}
}
catch (ex) { }
}
} else if (options && typeof url.URL === 'function' && options instanceof url.URL) {
return url.format(options);
@@ -140,9 +148,12 @@ class HttpDependencyParser extends RequestParser {
// so create them from the path, if path was specified
if (options.path && options.host) {
// need to force a protocol to make parameter valid - base url is required when input is a relative url
const parsedQuery = new url.URL(options.path, 'http://' + options.host + options.path);
options.pathname = parsedQuery.pathname;
options.search = parsedQuery.search;
try {
const parsedQuery = new url.URL(options.path, 'http://' + options.host + options.path);
options.pathname = parsedQuery.pathname;
options.search = parsedQuery.search;
}
catch (ex) { }
}

// Similarly, url.format ignores hostname and port if host is specified,
@@ -153,11 +164,14 @@ class HttpDependencyParser extends RequestParser {
if (options.host && options.port) {
// Force a protocol so it will parse the host as the host, not path.
// It is discarded and not used, so it doesn't matter if it doesn't match
const parsedHost = new url.URL(`http://${options.host}`);
if (!parsedHost.port && options.port) {
options.hostname = options.host;
delete options.host;
try {
const parsedHost = new url.URL(`http://${options.host}`);
if (!parsedHost.port && options.port) {
options.hostname = options.host;
delete options.host;
}
}
catch (ex) { }
}

// Mix in default values used by http.request and others
37 changes: 31 additions & 6 deletions AutoCollection/HttpRequestParser.ts
Original file line number Diff line number Diff line change
@@ -66,9 +66,17 @@ class HttpRequestParser extends RequestParser {
}

public getRequestTelemetry(baseTelemetry?: Contracts.Telemetry): Contracts.RequestTelemetry {

let name = this.method;
try {
name += " " + new url.URL(this.url).pathname;
}
catch (ex) { // Invalid URL
}

var requestTelemetry: Contracts.RequestTelemetry & Contracts.Identified = {
id: this.requestId,
name: this.method + " " + new url.URL(this.url).pathname,
name: name,
url: this.url,
/*
See https://github.com/microsoft/ApplicationInsights-dotnet-server/blob/25d695e6a906fbe977f67be3966d25dbf1c50a79/Src/Web/Web.Shared.Net/RequestTrackingTelemetryModule.cs#L250
@@ -136,7 +144,20 @@ class HttpRequestParser extends RequestParser {
}

public getOperationName(tags: { [key: string]: string }) {
return tags[HttpRequestParser.keys.operationName] || this.method + " " + new url.URL(this.url).pathname;
if(tags[HttpRequestParser.keys.operationName]){
return tags[HttpRequestParser.keys.operationName];
}
let pathName = "";
try {
pathName = new url.URL(this.url).pathname;
}
catch (ex) { // Invalid URL
}
let operationName = this.method;
if (pathName) {
operationName += " " + pathName;
}
return operationName;
}

public getRequestId() {
@@ -169,11 +190,15 @@ class HttpRequestParser extends RequestParser {
var protocol = (encrypted || request.headers["x-forwarded-proto"] == "https") ? "https" : "http";

var baseUrl = protocol + '://' + request.headers.host + '/';
var requestUrl = new url.URL(request.url, baseUrl);

var pathName = requestUrl.pathname;
var search = requestUrl.search;

var pathName = "";
var search = "";
try {
var requestUrl = new url.URL(request.url, baseUrl);
pathName = requestUrl.pathname;
search = requestUrl.search;
}
catch (ex) { }
var absoluteUrl = url.format({
protocol: protocol,
host: request.headers.host,
Loading