Skip to main content

Multiplayer Session Recorder

Project description

Session Recorder python

============================================================================

Introduction

The multiplayer-session-recorder module integrates OpenTelemetry with the Multiplayer platform to enable seamless trace collection and analysis. This library helps developers monitor, debug, and document application performance with detailed trace data. It supports flexible trace ID generation, sampling strategies.

Installation

To install the multiplayer-session-recorder module, use the following command:

pip install multiplayer-session-recorder

Optional Dependencies

The library supports optional dependencies for web framework integrations:

# For Django support
pip install multiplayer-session-recorder[django]

# For Flask support  
pip install multiplayer-session-recorder[flask]

# For both Django and Flask support
pip install multiplayer-session-recorder[all]

Session Recorder Initialization

from multiplayer_session_recorder import session_recorder

session_recorder.init({
  apiKey: "{YOUR_API_KEY}",
  traceIdGenerator: idGenerator,
  resourceAttributes: {
    serviceName: "{YOUR_APPLICATION_NAME}",
    version: "{YOUR_APPLICATION_VERSION}",
    environment: "{YOUR_APPLICATION_ENVIRONMENT}",
  }
})

Example Usage

from multiplayer_session_recorder import session_recorder, SessionType
// Session recorder trace id generator which is used during opentelemetry initialization
from .opentelemetry import id_generator

session_recorder.init({
  apiKey: "{YOUR_API_KEY}",
  traceIdGenerator: id_generator,
  resourceAttributes: {
    serviceName: "{YOUR_APPLICATION_NAME}",
    version: "{YOUR_APPLICATION_VERSION}",
    environment: "{YOUR_APPLICATION_ENVIRONMENT}",
  }
})

# ...

session_recorder.start(
    SessionType.PLAIN,
    {
      name: "This is test session",
      sessionAttributes: {
        accountId: "687e2c0d3ec8ef6053e9dc97",
        accountName: "Acme Corporation"
      }
    }
  )

  # do something here

  session_recorder.stop()

Session Recorder trace Id generator

from multiplayer_session_recorder import SessionRecorderTraceIdRatioBasedSampler

sampler = SessionRecorderTraceIdRatioBasedSampler(rate = 1/2)

Session Recorder trace id ratio based sampler

from multiplayer_session_recorder import SessionRecorderRandomIdGenerator

id_generator = SessionRecorderRandomIdGenerator(autoDocTracesRatio = 1/1000)

Django HTTP Payload Recorder Middleware

First, install Django support:

pip install multiplayer-session-recorder[django]

Then use the middleware in your Django settings:

from multiplayer_session_recorder import create_django_middleware

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    # Add the payload recorder middleware
    create_django_middleware({
        "captureBody": True,
        "captureHeaders": True,
        "maxPayloadSizeBytes": 10000,
        "isMaskBodyEnabled": True,
        "maskBodyFieldsList": ["password", "token"],
        "isMaskHeadersEnabled": True,
        "maskHeadersList": ["authorization"],
    }),
]

Flask HTTP Payload Recorder Middleware

First, install Flask support:

pip install multiplayer-session-recorder[flask]

Then use the middleware in your Flask application:

from flask import Flask
from multiplayer_session_recorder import create_flask_middleware

app = Flask(__name__)

# Create middleware functions
before_request, after_request = create_flask_middleware({
    "captureBody": True,
    "captureHeaders": True,
    "maxPayloadSizeBytes": 10000,
    "isMaskBodyEnabled": True,
    "maskBodyFieldsList": ["password", "secret"],
    "isMaskHeadersEnabled": True,
    "maskHeadersList": ["authorization"],
})

# Register the middleware
app.before_request(before_request)
app.after_request(after_request)

@app.route('/')
def hello():
    return 'Hello, World!'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multiplayer_session_recorder-0.2.2.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

multiplayer_session_recorder-0.2.2-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file multiplayer_session_recorder-0.2.2.tar.gz.

File metadata

File hashes

Hashes for multiplayer_session_recorder-0.2.2.tar.gz
Algorithm Hash digest
SHA256 c6bc4f20512933acfba97a742c896804f038efb03cdfa9596b0f18d3d1a74bcc
MD5 93cdab3d6ec55d652b480a52afb56e2c
BLAKE2b-256 238abbe19ba96f176cd060aeb5e27271abbb9a4370a893ace50e13baca123262

See more details on using hashes here.

File details

Details for the file multiplayer_session_recorder-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for multiplayer_session_recorder-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 170b7abf5ed96326142cce084f551877e9178cb9a24000a053655b1594c8767a
MD5 f783408750384705b69e6861b22a10f6
BLAKE2b-256 aa256025d59483c5d06d17ab6594270cb9b4700d8595c95e3236d67338cf8660

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page