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

Add instrumentation support to the typescript code #12991

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

fearthecowboy
Copy link
Member

This adds the instrumentation support to enable performance testing and monitoring.

It:

  • cleaned up some calls to logging so that we're not over-importing in typescript
  • patches the logging so that log messages are sent to the collector.
  • adds calls to monkey-patch vscode, the client and the providers so that we get monitoring events for as much as possible.
  • if the PERFECTO_LAUNCH_SETTINGS environment variable is not set, everything here is a no-op
  • the actual instrumentation code is loaded by the perfecto tool

@fearthecowboy fearthecowboy requested a review from a team as a code owner November 22, 2024 21:30
import { CppBuildTask, CppBuildTaskDefinition, cppBuildTaskProvider } from '../LanguageServer/cppBuildTaskProvider';
import { configPrefix } from '../LanguageServer/extension';
import { CppSettings, OtherSettings } from '../LanguageServer/settings';
import { getOutputChannel, getOutputChannelLogger, Logger, showOutputChannel } from '../logger';
Copy link
Member

Choose a reason for hiding this comment

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

It's unclear to me why this is changing. It doesn't seem related to the purpose of this PR. Can you revert this file?

@@ -7,7 +7,7 @@
import * as vscode from 'vscode';
import { localize } from 'vscode-nls';
import * as util from '../common';
import * as logger from '../logger';
import { getOutputChannelLogger } from '../logger';
Copy link
Member

Choose a reason for hiding this comment

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

It's unclear to me why this is changing. It doesn't seem related to the purpose of this PR. Can you revert this file?

@@ -8,7 +8,7 @@ import * as vscode from 'vscode';
import { Position, TextDocumentIdentifier } from 'vscode-languageclient';
import * as nls from 'vscode-nls';
import * as util from '../common';
import * as logger from '../logger';
import { getOutputChannel } from '../logger';
Copy link
Member

Choose a reason for hiding this comment

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

It's unclear to me why this is changing. It doesn't seem related to the purpose of this PR. Can you revert this file?


public append(level: number, message: string): void;
public append(message: string): void;
public append(levelOrMessage: string | number, message?: string): void {
Copy link
Member

Choose a reason for hiding this comment

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

I understand why you did this, but I'm not a fan of this pattern (the optional parameter is the first arg). Since we don't want to put the loggingLevel second, I'd prefer we not change the logging API until we're ready to change it everywhere in the code.

Suggestion: Create a new API taking the level and the message and deprecate the old one. Then we can migrate the rest of the extension to it in a separate PR.

message = message || levelOrMessage as string;
const hasLevel = typeof levelOrMessage === 'number';

if (!hasLevel || getLoggingLevel() >= levelOrMessage) {
Copy link
Member

Choose a reason for hiding this comment

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

This being a semi-high-frequency function, perhaps the current logging level should be stored on the Logger as a field instead of having to call a function every time.

public append(level: number, message: string): void;
public append(message: string): void;
public append(levelOrMessage: string | number, message?: string): void {
message = message || levelOrMessage as string;
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible for levelOrMessage to be a number when message is not passed in? Better to test the inputs with the isString isNumber helpers than to assert with as. (though my preference is to remove the overloads and create a new API that can forward here for logging to the output channel when the checks pass)

import * as plist from 'plist';
import * as nls from 'vscode-nls';
import { LinuxDistribution } from './linuxDistribution';
import { getOutputChannelLogger, showOutputChannel } from './logger';
Copy link
Member

Choose a reason for hiding this comment

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

It's unclear to me why this is changing. It doesn't seem related to the purpose of this PR. Can you revert this file?

}

// If the instrumentation object was loaded then we can set the services from the global object
if ((global as any).instrumentation) {
Copy link
Member

Choose a reason for hiding this comment

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

Use isInstrumentationEnabled here or connect it to the last block with an else?

}

export function getLoggingLevel() {
return getNumericLoggingLevel(vscode.workspace.getConfiguration("C_Cpp", null).get<string>("loggingLevel"));
Copy link
Member

Choose a reason for hiding this comment

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

Since we can't pull CppSettings into this module, maybe we need to split out the validation code because we shouldn't be reading raw settings in the extension anymore. Apparently this file was skipped due to it not using CppSettings.

This isn't necessarily your problem. I'm just thinking out loud.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Pull Request
Development

Successfully merging this pull request may close these issues.

2 participants