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

refactor: add plugin improvement #12324

Merged
merged 4 commits into from
Sep 3, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading