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.10.tar.gz (11.5 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.10-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for multiplayer_session_recorder-0.2.10.tar.gz
Algorithm Hash digest
SHA256 d8e6f226400a24c2c61425264168cb25723e17462084ce574fec7227fd841032
MD5 aa7f2d64cf4485535482aaa13723946a
BLAKE2b-256 7967f620d0819cd5c75e9ecb7a03c56edff354da4efb2b119755d30293b77ca4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multiplayer_session_recorder-0.2.10-py3-none-any.whl
Algorithm Hash digest
SHA256 c5fbee945b035422e091e0c53cca4ac5ced3fdbfbabeca4fdc5069c3753d4ec0
MD5 2c6806bbc547b95d0aff73f3281b76c8
BLAKE2b-256 67eb449da21a0bf86c1a1f8daad57b3cf7266d7a672f71750ba92a0e02bf8a81

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