Skip to content

Commit

Permalink
refactor: add plugin improvement (#12324)
Browse files Browse the repository at this point in the history
* refactor: add help link

* fix: cid

* refactor: telemetry improvememnt

* test: ut
  • Loading branch information
yuqizhou77 authored Sep 3, 2024
1 parent 39776b8 commit acb8134
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/userInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class CLIUserInteraction implements UserInteraction {
const newConfig: InputTextConfig = {
name: config.name,
title: config.title,
default: (config.default as string) || "./",
default: config.default as string,
validation: config.validation || pathValidation,
};
return this.inputText(newConfig);
Expand Down
2 changes: 1 addition & 1 deletion packages/fx-core/src/component/utils/envFunctionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { DriverContext } from "../driver/interface/commonArgs";

const source = "ResolveManifestFunction";
const telemetryEvent = "manifest-with-function";
const helpLink = undefined; // TODO: update link
const helpLink = "https://aka.ms/teamsfx-customize-manifest";

enum TelemetryPropertyKey {
manifestType = "manifest-type",
Expand Down
10 changes: 3 additions & 7 deletions packages/fx-core/src/core/FxCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import {
CreateProjectResult,
CryptoProvider,
DefaultApiSpecFolderName,
DefaultApiSpecJsonFileName,
DefaultApiSpecYamlFileName,
DefaultPluginManifestFileName,
Func,
FxError,
IGenerator,
Expand All @@ -42,7 +39,6 @@ import {
import { DotenvParseOutput } from "dotenv";
import fs from "fs-extra";
import * as jsonschema from "jsonschema";
import { OpenAPIV3 } from "openapi-types";
import * as os from "os";
import * as path from "path";
import "reflect-metadata";
Expand All @@ -64,7 +60,7 @@ import {
isValidProjectV3,
} from "../common/projectSettingsHelper";
import { ProjectTypeResult, projectTypeChecker } from "../common/projectTypeChecker";
import { TelemetryEvent, TelemetryProperty, telemetryUtils } from "../common/telemetry";
import { TelemetryEvent, telemetryUtils } from "../common/telemetry";
import { MetadataV3, VersionSource, VersionState } from "../common/versionMetadata";
import { ActionInjector } from "../component/configManager/actionInjector";
import { ILifecycle, LifecycleName } from "../component/configManager/interface";
Expand Down Expand Up @@ -1741,7 +1737,7 @@ export class FxCore {
manifestPath,
inputs,
context,
CoreTelemetryComponentName,
"copilotPluginAddAPI",
isPlugin ? ProjectType.Copilot : ProjectType.SME,
{
destinationApiSpecFilePath: outputApiSpecPath,
Expand Down Expand Up @@ -1943,7 +1939,7 @@ export class FxCore {
teamsManifestPath,
inputs,
context,
CoreTelemetryComponentName,
Stage.addPlugin,
ProjectType.Copilot,
{
destinationApiSpecFilePath: destinationApiSpecPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export class VSCodeTelemetryReporter extends vscode.Disposable implements Teleme
}

this.checkAndOverwriteSharedProperty(properties);
properties[TelemetryProperty.CorrelationId] = Correlator.getId();
if (properties[TelemetryProperty.CorrelationId] == undefined) {
properties[TelemetryProperty.CorrelationId] = Correlator.getId();
}

const featureFlags = featureFlagManager.listEnabled();
properties[TelemetryProperty.FeatureFlags] = featureFlags ? featureFlags.join(";") : "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ describe("vscodeTelemetryReporter", () => {
let tester: VSCodeTelemetryReporter;
const sandbox = sinon.createSandbox();
const reporterStub = new MockTelemetryReporter();
const sendTelemetryErrorEventSpy = sandbox.spy(reporterStub, "sendTelemetryErrorEvent");
const sendTelemetryEventSpy = sandbox.spy(reporterStub, "sendTelemetryEvent");
const sendTelemetryExceptionSpy = sandbox.spy(reporterStub, "sendTelemetryException");
let sendTelemetryEventSpy: sinon.SinonSpy;
let sendTelemetryExceptionSpy: sinon.SinonSpy;
let sendTelemetryErrorEventSpy: sinon.SinonSpy;

before(() => {
beforeEach(() => {
tester = new VSCodeTelemetryReporter(
"test",
"1.0.0-rc.1",
Expand All @@ -32,9 +32,13 @@ describe("vscodeTelemetryReporter", () => {
tester.addSharedProperty("programming-language", "");
tester.addSharedProperty("host-type", "");
tester.addSharedProperty("is-from-sample", "");

sendTelemetryEventSpy = sandbox.spy(reporterStub, "sendTelemetryEvent");
sendTelemetryExceptionSpy = sandbox.spy(reporterStub, "sendTelemetryException");
sendTelemetryErrorEventSpy = sandbox.spy(reporterStub, "sendTelemetryErrorEvent");
});

after(() => {
afterEach(() => {
tester.dispose();
sandbox.restore();
});
Expand Down Expand Up @@ -90,6 +94,35 @@ describe("vscodeTelemetryReporter", () => {
);
});

it("sendTelemetryErrorEvent: not overwrite correlationId if existing", () => {
tester.sendTelemetryErrorEvent(
"sampleErrorEvent",
{
stringProp: "some string",
"error-stack": "some user stack trace at (C:/fake_path/fake_file:1:1)",
"correlation-id": "fakeId",
},
{ numericMeasure: 123 },
["error-stack"]
);

sinon.assert.calledOnceWithMatch(
sendTelemetryErrorEventSpy,
"sampleErrorEvent",
{
stringProp: "some string",
"error-stack": "some user stack trace at (<REDACTED: user-file-path>/fake_file:1:1)",
"project-id": "",
"correlation-id": "fakeId",
"feature-flags": featureFlags,
"programming-language": "",
"host-type": "",
"is-from-sample": "",
},
{ numericMeasure: 123 }
);
});

it("sendTelemetryException", () => {
const error = new Error("error for test");
tester.sendTelemetryException(error, { stringProp: "some string" }, { numericMeasure: 123 });
Expand Down

0 comments on commit acb8134

Please sign in to comment.