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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for multiplayer_session_recorder-0.2.8.tar.gz
Algorithm Hash digest
SHA256 5c0db85d2ed15a282dc3a2df457cc57491604ffbd1035625ac2b762928f03238
MD5 49935625e06742dec592040ba9daf59e
BLAKE2b-256 8c4fb14c566a5c1ecb59d0a6e46b507348d57578b41e13e53bfd2123487be554

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multiplayer_session_recorder-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 6417c30dd14ee564527a28d75f63b59188ee35950b7db7c9a30de5409bfbc5a6
MD5 89dfb63d03bc28a74fea1701dc4bc3af
BLAKE2b-256 987c8778baff6833a888857962076942707a0a3b454a66141fc3241ffc56e908

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