---
title: client | CodeWeaver Docs
description: API reference for codeweaver.core.telemetry.client
url: "https://docs.knitli.com/api/core/telemetry/client"
type: static
generatedAt: "2026-04-17T17:21:08.106Z"
---

# client
       [Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftelemetry%2Fclient%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftelemetry%2Fclient%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[View in Markdown](/codeweaver/api/core/telemetry/client.md)       [Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftelemetry%2Fclient%2F)[Share on X](https://x.com/intent/tweet?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftelemetry%2Fclient%2F&text=client)[Share on Threads](https://threads.net/intent/post?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftelemetry%2Fclient%2F&text=client)[Share on Bluesky](https://bsky.app/intent/compose?text=client%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftelemetry%2Fclient%2F)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftelemetry%2Fclient%2F)[Share on Reddit](https://reddit.com/submit?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftelemetry%2Fclient%2F&title=client)[Share on Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftelemetry%2Fclient%2F&t=client)[Share on Email](mailto:?subject=client&body=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftelemetry%2Fclient%2F)[Share on WhatsApp](https://wa.me/?text=client%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftelemetry%2Fclient%2F)[Share on Telegram](https://t.me/share/url?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Ftelemetry%2Fclient%2F&text=client)
# `codeweaver.core.telemetry.client`
[Section titled “codeweaver.core.telemetry.client”](#codeweavercoretelemetryclient)
PostHog telemetry client wrapper with context API support.

Provides a privacy-aware wrapper around the PostHog Python client with:

 - PostHog v7 context API for session tracking and shared tags
 - Privacy filtering via serialize_for_telemetry() on data models
 - Error handling (telemetry never crashes the application)
 - Easy configuration and opt-out
 - Feature flag support for A/B testing

## Class: `TelemetryService`
[Section titled “Class: TelemetryService”](#class-telemetryservice)
Privacy-aware PostHog client wrapper with context API support.

Handles telemetry event sending with error handling and configuration management. Uses PostHog v7 context API for session tracking and shared properties. Privacy filtering is handled via serialize_for_telemetry() on BasedModel and DataclassSerializationMixin objects before passing to capture().

Example: >>> client = TelemetryService.from_settings() >>> client.start_session({“version”: “0.5.0”}) >>> if client.enabled: … client.capture(“codeweaver_search”, {“intent”: “UNDERSTAND”}) >>> client.end_session()

### Method: `capture`
[Section titled “Method: capture”](#method-capture)

**

```
capture()
```

Send event to PostHog with privacy controls.

Args: event: Event name properties: Event properties dictionary (should already be privacy-filtered) distinct_id: Optional user identifier (default: session_id for privacy)

Note: This method never raises exceptions. All errors are logged but do not affect application execution.

Properties should be privacy-safe. Use serialize_for_telemetry() on objects before passing properties to ensure sensitive data is filtered.

The $process_person_profile property is automatically set to False to ensure privacy-respecting anonymous events.

### Method: `capture_from_event`
[Section titled “Method: capture_from_event”](#method-capture_from_event)

**

```
capture_from_event()
```

Send event from a TelemetryEvent object.

Args: event_obj: Object implementing TelemetryEvent protocol

### Method: `capture_with_serialization`
[Section titled “Method: capture_with_serialization”](#method-capture_with_serialization)

**

```
capture_with_serialization()
```

Send event with automatic privacy serialization.

Args: event: Event name data_obj: Object with serialize_for_telemetry() method (BasedModel or DataclassSerializationMixin) distinct_id: Optional distinct ID (defaults to session_id)

Note: This method automatically calls serialize_for_telemetry() on the data object to ensure sensitive fields are filtered according to _telemetry_keys().

### Method: `end_session`
[Section titled “Method: end_session”](#method-end_session)

**

```
end_session()
```

Clean up context and flush pending events.

Should be called at application shutdown to ensure all events are sent before exit.

### Method: `from_settings`
[Section titled “Method: from_settings”](#method-from_settings)

**

```
from_settings()
```

Create PostHog client from telemetry settings.

Returns: Configured PostHog client instance

### Method: `get_all_feature_flags`
[Section titled “Method: get_all_feature_flags”](#method-get_all_feature_flags)

**

```
get_all_feature_flags()
```

Get all feature flags for the current session.

Returns: Dictionary of flag key to variant value

### Method: `get_feature_flag`
[Section titled “Method: get_feature_flag”](#method-get_feature_flag)

**

```
get_feature_flag()
```

Get feature flag value for the current session.

Args: flag_key: Feature flag key

Returns: Feature flag variant value or None if not found/disabled

### Method: `shutdown`
[Section titled “Method: shutdown”](#method-shutdown)

**

```
shutdown()
```

Flush pending events and close client.

Should be called at application shutdown to ensure all events are sent before exit.

### Method: `start_session`
[Section titled “Method: start_session”](#method-start_session)

**

```
start_session()
```

Initialize PostHog context for the session.

Sets up session tracking and shared tags that will be inherited by all events captured during this session.

Args: metadata: Optional metadata dict with keys like ‘version’, ‘backend’, etc.

## Function: `get_telemetry_client`
[Section titled “Function: get_telemetry_client”](#function-get_telemetry_client)

**

```
get_telemetry_client()
```

Get singleton telemetry client instance.

Returns: Cached PostHog client configured from settings