Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dependency name could be null #597

Merged
merged 4 commits into from Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions Library/EnvelopeFactory.ts
Expand Up @@ -115,7 +115,9 @@ class EnvelopeFactory {

private static createDependencyData(telemetry: Contracts.DependencyTelemetry & Contracts.Identified): Contracts.Data<Contracts.RemoteDependencyData> {
var remoteDependency = new Contracts.RemoteDependencyData();
remoteDependency.name = telemetry.name.length > 1024 ? telemetry.name.slice(0, 1021) + '...' : telemetry.name;
if (typeof telemetry.name === "string") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When null you will not send a name, is this not causing issues during ingestion?, maybe having default empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name is not required for ingestion. Really the typings are wrong, but they are autogenerated from the bond files and so I would like to avoid creating discrepancies across language SDKs by making a one-off change for our types

remoteDependency.name = telemetry.name.length > 1024 ? telemetry.name.slice(0, 1021) + '...' : telemetry.name;
}
remoteDependency.data = telemetry.data;
remoteDependency.target = telemetry.target;
remoteDependency.duration = Util.msToTimeSpan(telemetry.duration);
Expand Down Expand Up @@ -223,7 +225,7 @@ class EnvelopeFactory {
telemetry: Contracts.AvailabilityTelemetry & Contracts.Identified,
): Contracts.Data<Contracts.AvailabilityData> {
let availabilityData = new Contracts.AvailabilityData();

if (telemetry.id) {
availabilityData.id = telemetry.id;
} else {
Expand Down
24 changes: 20 additions & 4 deletions Tests/Library/EnvelopeFactoryTests.ts
Expand Up @@ -8,7 +8,7 @@ import Client = require("../../Library/TelemetryClient");
import Util = require("../../Library/Util");

describe("Library/EnvelopeFactory", () => {

var properties: { [key: string]: string; } = { p1: "p1", p2: "p2", common: "commonArg" };
var mockData = <any>{ baseData: { properties: {} }, baseType: "BaseTestData" };
describe("#createEnvelope()", () => {
Expand Down Expand Up @@ -39,7 +39,7 @@ describe("Library/EnvelopeFactory", () => {
});

it("should allow tags to be overwritten", () => {

var client = new Client("key");
var env = EnvelopeFactory.createEnvelope(<Contracts.EventTelemetry>{name:"name"}, Contracts.TelemetryType.Event, commonproperties, client.context, client.config);
assert.deepEqual(env.tags, client.context.tags, "tags are set by default");
Expand All @@ -58,6 +58,22 @@ describe("Library/EnvelopeFactory", () => {
assert.equal(envelope.name, "Microsoft.ApplicationInsights.key.Event");
});
});

describe("#createDependencyData()", () => {
it("should accept a telemetry item without a name", () => {
assert.doesNotThrow(() => {
var envelope = EnvelopeFactory.createEnvelope(<Contracts.DependencyTelemetry>{
name: null,
data: "GET https://example.com",
duration: 123,
success: true,
resultCode: 200
}, Contracts.TelemetryType.Dependency);
assert.equal((envelope.data as Contracts.Data<Contracts.RemoteDependencyData>).baseData.name, undefined);
});
});
});

describe("#createExceptionData()", () => {
var simpleError: Error;

Expand Down Expand Up @@ -141,9 +157,9 @@ describe("Library/EnvelopeFactory", () => {
it("creates data with given content", () => {
var envelope = EnvelopeFactory.createEnvelope(availabilityTelemetry, Contracts.TelemetryType.Availability);
var data = <Contracts.Data<Contracts.AvailabilityData>>envelope.data;

assert.deepEqual(data.baseType, "AvailabilityData");

assert.deepEqual(data.baseData.id, availabilityTelemetry.id);
assert.deepEqual(data.baseData.measurements, availabilityTelemetry.measurements);
assert.deepEqual(data.baseData.success, availabilityTelemetry.success);
Expand Down