Skip to content

Commit

Permalink
Add option to log tracing info in agent logs (#3233)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkukielka authored Feb 22, 2024
1 parent 26e34f6 commit 4e5bd02
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions agent/src/AgentWorkspaceConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export class AgentWorkspaceConfiguration implements vscode.WorkspaceConfiguratio
return extensionConfig?.debug ?? false
case 'cody.debug.verbose':
return extensionConfig?.verboseDebug ?? false
case 'cody.experimental.tracing':
return extensionConfig?.verboseDebug ?? false
case 'cody.autocomplete.experimental.syntacticPostProcessing':
// False because we don't embed WASM with the agent yet.
return false
Expand Down
9 changes: 5 additions & 4 deletions vscode/src/extension.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import { ExtensionApi } from './extension-api'
import type { LocalEmbeddingsConfig, LocalEmbeddingsController } from './local-context/local-embeddings'
import type { SymfRunner } from './local-context/symf'
import { start } from './main'
import type { OpenTelemetryService } from './services/open-telemetry/OpenTelemetryService.node'
import type {
OpenTelemetryService,
OpenTelemetryServiceConfig,
} from './services/open-telemetry/OpenTelemetryService.node'
import { captureException, type SentryService } from './services/sentry/sentry'
import type { CommandsProvider } from './commands/services/provider'

Expand All @@ -35,9 +38,7 @@ export interface PlatformContext {
| Constructor<typeof SourcegraphBrowserCompletionsClient>
| Constructor<typeof SourcegraphNodeCompletionsClient>
createSentryService?: (config: Pick<ConfigurationWithAccessToken, 'serverEndpoint'>) => SentryService
createOpenTelemetryService?: (
config: Pick<ConfigurationWithAccessToken, 'serverEndpoint' | 'experimentalTracing'>
) => OpenTelemetryService
createOpenTelemetryService?: (config: OpenTelemetryServiceConfig) => OpenTelemetryService
onConfigurationChange?: (configuration: Configuration) => void
}

Expand Down
1 change: 1 addition & 0 deletions vscode/src/external-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type ExternalServicesConfiguration = Pick<
| 'customHeaders'
| 'accessToken'
| 'debugEnable'
| 'debugVerbose'
| 'experimentalTracing'
> &
LocalEmbeddingsConfig
Expand Down
10 changes: 6 additions & 4 deletions vscode/src/services/open-telemetry/OpenTelemetryService.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import { version } from '../../version'
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base'
import { ConsoleBatchSpanExporter } from './console-batch-span-exporter'

type OpenTelemetryServiceConfig = Pick<
export type OpenTelemetryServiceConfig = Pick<
ConfigurationWithAccessToken,
'serverEndpoint' | 'experimentalTracing'
'serverEndpoint' | 'experimentalTracing' | 'debugVerbose'
>

export class OpenTelemetryService {
Expand Down Expand Up @@ -50,7 +50,9 @@ export class OpenTelemetryService {
return
}
this.lastTraceUrl = traceUrl
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ERROR)

const logLevel = this.config.debugVerbose ? DiagLogLevel.DEBUG : DiagLogLevel.ERROR
diag.setLogger(new DiagConsoleLogger(), logLevel)

await this.sdk?.shutdown()
this.sdk = undefined
Expand All @@ -66,7 +68,7 @@ export class OpenTelemetryService {
// Disable default process logging. We do not care about the VS Code extension process
autoDetectResources: false,

...(process.env.NODE_ENV === 'development' && {
...((process.env.NODE_ENV === 'development' || this.config.debugVerbose) && {
spanProcessor: new BatchSpanProcessor(new ConsoleBatchSpanExporter()),
}),
})
Expand Down

0 comments on commit 4e5bd02

Please sign in to comment.