import { Project , SourceFile , VariableDeclarationKind } from "ts-morph" ; import { PackageDetails } from "../models/packageDetails" ; import { NameType , normalizeName } from "../utils/nameUtils" ; import { getAutorestOptions } from "../autorestSession" ; export function generateTracingFile ( project ) { const { tracingInfo , srcPath } = getAutorestOptions ( ) ; if ( tracingInfo === undefined ) { return ; } const file = project . createSourceFile ( `${ srcPath }/tracing.ts` , undefined , { overwrite : true } ) ; file . addImportDeclarations ( [ { namedImports : [ "createSpanFunction" ] , moduleSpecifier : "@azure/core-tracing" } ] ) ; writeCreateSpanFunction ( file ) ; file . fixUnusedIdentifiers ( ) ; } function writeCreateSpanFunction ( file ) { const { tracingInfo } = getAutorestOptions ( ) ; if ( ! tracingInfo ) { return ; } file . addVariableStatement ( { isExported : true , declarationKind : VariableDeclarationKind . Const , declarations : [ { name : "createSpan" , initializer : `createSpanFunction({
        namespace: "${ tracingInfo . namespace }",
        packagePrefix: "${ tracingInfo . packagePrefix }"
      });` } ] } ) ; } function getTelemetryPackageName ( { nameWithoutScope } ) { return nameWithoutScope . split ( /[-._ ]+/ ) . map ( part => normalizeName ( part , NameType . Class ) ) ; } function getTelemetryNamespace ( packageDetails ) { const { scopeName } = packageDetails ; return [ ... ( scopeName ? [ scopeName ] : [ ] ) , ... getTelemetryPackageName ( packageDetails ) ] . map ( part => normalizeName ( part , NameType . Class ) ) . join ( "." ) ; }