| 946 | } |
| 947 | |
| 948 | export function setMeter( |
| 949 | meter: Meter, |
| 950 | createCounter: (name: string, options: MetricOptions) => AttributedCounter, |
| 951 | ): void { |
| 952 | STATE.meter = meter |
| 953 | |
| 954 | // Initialize all counters using the provided factory |
| 955 | STATE.sessionCounter = createCounter('claude_code.session.count', { |
| 956 | description: 'Count of CLI sessions started', |
| 957 | }) |
| 958 | STATE.locCounter = createCounter('claude_code.lines_of_code.count', { |
| 959 | description: |
| 960 | "Count of lines of code modified, with the 'type' attribute indicating whether lines were added or removed", |
| 961 | }) |
| 962 | STATE.prCounter = createCounter('claude_code.pull_request.count', { |
| 963 | description: 'Number of pull requests created', |
| 964 | }) |
| 965 | STATE.commitCounter = createCounter('claude_code.commit.count', { |
| 966 | description: 'Number of git commits created', |
| 967 | }) |
| 968 | STATE.costCounter = createCounter('claude_code.cost.usage', { |
| 969 | description: 'Cost of the Claude Code session', |
| 970 | unit: 'USD', |
| 971 | }) |
| 972 | STATE.tokenCounter = createCounter('claude_code.token.usage', { |
| 973 | description: 'Number of tokens used', |
| 974 | unit: 'tokens', |
| 975 | }) |
| 976 | STATE.codeEditToolDecisionCounter = createCounter( |
| 977 | 'claude_code.code_edit_tool.decision', |
| 978 | { |
| 979 | description: |
| 980 | 'Count of code editing tool permission decisions (accept/reject) for Edit, Write, and NotebookEdit tools', |
| 981 | }, |
| 982 | ) |
| 983 | STATE.activeTimeCounter = createCounter('claude_code.active_time.total', { |
| 984 | description: 'Total active time in seconds', |
| 985 | unit: 's', |
| 986 | }) |
| 987 | } |
| 988 | |
| 989 | export function getMeter(): Meter | null { |
| 990 | return STATE.meter |