Skip to content

Commit 1e7105a

Browse files
committed
feat: updated README
1 parent e8c7a67 commit 1e7105a

File tree

10 files changed

+91
-24
lines changed

10 files changed

+91
-24
lines changed

README.md

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ require 'opentelemetry/exporter/otlp'
6969
# see: Multiplayer::SessionRecorder::Exporters::SessionRecorderGrpcTraceExporter
7070
# and Multiplayer::SessionRecorder::Exporters::SessionRecorderGrpcLogsExporter
7171
multiplayer_trace_exporter = Multiplayer::SessionRecorder::Exporters::SessionRecorderHttpTraceExporter.new(
72-
api_key: "MULTIPLAYER_OTLP_KEY" # note: replace with your Multiplayer OTLP key
72+
api_key: "MULTIPLAYER_API_KEY" # note: replace with your Multiplayer API key
7373
)
7474
multiplayer_log_exporter = Multiplayer::SessionRecorder::Exporters::SessionRecorderHttpLogsExporter.new(
75-
api_key: "MULTIPLAYER_OTLP_KEY" # note: replace with your Multiplayer OTLP key
75+
api_key: "MULTIPLAYER_API_KEY" # note: replace with your Multiplayer API key
7676
)
7777

7878
# Multiplayer exporter wrappers filter out session recording attributes before passing to provided exporter
@@ -193,6 +193,8 @@ Use the following code below to initialize and run the session recorder.
193193

194194
Example for Session Recorder initialization relies on [opentelemetry.rb](./examples/cli/opentelemetry.rb) file. Copy that file and put next to quick start code.
195195

196+
### Initialize
197+
196198
```ruby
197199
# IMPORTANT: set up OpenTelemetry
198200
# for an example see ./examples/cli/opentelemetry.rb
@@ -206,21 +208,27 @@ opentelemetry_components = OpenTelemetryConfig.setup
206208
# Initialize SessionRecorder
207209
session_recorder = Multiplayer::SessionRecorder::SessionRecorder.new
208210
session_recorder.init({
209-
api_key: "MULTIPLAYER_OTLP_KEY", # note: replace with your Multiplayer OTLP key
211+
api_key: "MULTIPLAYER_API_KEY", # note: replace with your Multiplayer API key
210212
trace_id_generator: opentelemetry_components[:id_generator],
211213
resource_attributes: {
212214
component_name: "{YOUR_APPLICATION_NAME}",
213215
component_version: "{YOUR_APPLICATION_VERSION}",
214216
environment: "{YOUR_APPLICATION_ENVIRONMENT}"
215217
}
216218
})
219+
```
220+
221+
### Manual session recording
217222

223+
Below is an example showing how to create a session recording in `MANUAL` mode. Manual session recordings stream and save all the data between calling `start` and `stop`.
224+
225+
```ruby
218226
session_recorder.start(
219-
Multiplayer::SessionRecorder::Type::SessionType::PLAIN,
227+
Multiplayer::SessionRecorder::Type::SessionType::MANUAL,
220228
{
221229
name: "This is test session",
222230
resource_attributes: {
223-
account_id: "687e2c0d3ec8ef6053e9dc97",
231+
account_id: "1234",
224232
account_name: "Acme Corporation"
225233
}
226234
}
@@ -235,6 +243,65 @@ session_recorder.stop({
235243
})
236244
```
237245

246+
### Continuous session recording
247+
248+
Below is an example showing how to create a session in `CONTINUOUS` mode. Continuous session recordings **stream** all the data received between calling `start` and `stop` -
249+
but only **save** a rolling window data (90 seconds by default) when:
250+
251+
- an exception or error occurs;
252+
- when `save` is called; or
253+
- programmatically, when the auto-save attribute is attached to a span.
254+
255+
```ruby
256+
session_recorder.start(
257+
Multiplayer::SessionRecorder::Type::SessionType::CONTINUOUS,
258+
{
259+
name: "This is test session",
260+
resource_attributes: {
261+
account_id: "1234",
262+
account_name: "Acme Corporation"
263+
}
264+
}
265+
)
266+
267+
# do something here
268+
269+
session_recorder.save()
270+
271+
# do something here
272+
273+
session_recorder.save()
274+
275+
# do something here
276+
277+
session_recorder.stop({
278+
sessionAttributes: {
279+
comment: "Session completed successfully"
280+
}
281+
})
282+
```
283+
284+
Continuous session recordings may also be saved from within any service or component involved in a trace by adding the attributes below to a span:
285+
286+
```ruby
287+
require 'opentelemetry-api'
288+
require 'multiplayer-session-recorder'
289+
290+
active_span = OpenTelemetry::Trace.current_span
291+
292+
if active_span.context.valid?
293+
active_span.set_attribute(
294+
MultiplayerApp::SessionRecorder::ATTR_MULTIPLAYER_CONTINUOUS_SESSION_AUTO_SAVE,
295+
true
296+
)
297+
298+
active_span.set_attribute(
299+
MultiplayerApp::SessionRecorder::ATTR_MULTIPLAYER_CONTINUOUS_SESSION_AUTO_SAVE_REASON,
300+
"Some reason"
301+
)
302+
end
303+
```
304+
238305
Replace the placeholders with your application’s version, name, environment, and API key.
239306

240307
## License

example_opentelemetry.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
SERVICE_NAME = "<service_name>"
1111
SERVICE_VERSION = "<service_version>"
1212
PLATFORM_ENV = "<environment_name>"
13-
MULTIPLAYER_OTLP_KEY = ENV["MULTIPLAYER_OTLP_KEY"]
13+
MULTIPLAYER_API_KEY = ENV["MULTIPLAYER_API_KEY"]
1414
HOSTNAME = Socket.gethostname
1515

1616
## Session Recorder Exporter configuration
17-
session_exporter = SessionRecorder::Exporters.create_http_trace_exporter(api_key: MULTIPLAYER_OTLP_KEY)
17+
session_exporter = SessionRecorder::Exporters.create_http_trace_exporter(api_key: MULTIPLAYER_API_KEY)
1818

1919
OpenTelemetry::SDK.configure do |c|
2020
# Set processor for SessionRecorder::Exporters

examples/cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
### Launch
99
```bash
10-
MULTIPLAYER_OTLP_KEY="your-key" ENVIRONMENT="staging" bundle exec ruby main.rb
10+
MULTIPLAYER_API_KEY="your-key" ENVIRONMENT="staging" bundle exec ruby main.rb
1111
```

examples/cli/config.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Configuration for the CLI example
44
module Config
55
# OpenTelemetry API configuration
6-
MULTIPLAYER_OTLP_KEY = ENV['MULTIPLAYER_OTLP_KEY'] || 'your-api-key-here'
6+
MULTIPLAYER_API_KEY = ENV['MULTIPLAYER_API_KEY'] || 'your-api-key-here'
77
MULTIPLAYER_TRACES_ENDPOINT = ENV['MULTIPLAYER_TRACES_ENDPOINT'] || 'https://api.multiplayer.com/v1/otlp/traces'
88
MULTIPLAYER_LOGS_ENDPOINT = ENV['MULTIPLAYER_LOGS_ENDPOINT'] || 'https://api.multiplayer.com/v1/otlp/logs'
99

@@ -34,16 +34,16 @@ def self.display_config
3434
puts " Log Level: #{LOG_LEVEL}"
3535
puts " Traces Endpoint: #{MULTIPLAYER_TRACES_ENDPOINT}"
3636
puts " Logs Endpoint: #{MULTIPLAYER_LOGS_ENDPOINT}"
37-
puts " API Key: #{MULTIPLAYER_OTLP_KEY[0..8]}..." if MULTIPLAYER_OTLP_KEY != 'your-api-key-here'
37+
puts " API Key: #{MULTIPLAYER_API_KEY[0..8]}..." if MULTIPLAYER_API_KEY != 'your-api-key-here'
3838
puts ""
3939
end
4040

4141
# Validate required configuration
4242
def self.validate
4343
errors = []
4444

45-
if MULTIPLAYER_OTLP_KEY == 'your-api-key-here'
46-
errors << "MULTIPLAYER_OTLP_KEY must be set to a valid API key"
45+
if MULTIPLAYER_API_KEY == 'your-api-key-here'
46+
errors << "MULTIPLAYER_API_KEY must be set to a valid API key"
4747
end
4848

4949
if errors.any?

examples/cli/main.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def init
4545
# Initialize SessionRecorder
4646
@logger.info("🎯 Initializing SessionRecorder...")
4747
@session_recorder.init({
48-
api_key: Config::MULTIPLAYER_OTLP_KEY,
48+
api_key: Config::MULTIPLAYER_API_KEY,
4949
trace_id_generator: opentelemetry_components[:id_generator],
5050
resource_attributes: {
5151
component_name: Config::COMPONENT_NAME,
@@ -57,7 +57,7 @@ def init
5757
@logger.info("✅ Application initialized successfully")
5858
@logger.info(" Component: #{Config::COMPONENT_NAME} v#{Config::COMPONENT_VERSION}")
5959
@logger.info(" Environment: #{Config::ENVIRONMENT}")
60-
@logger.info(" API Key: #{Config::MULTIPLAYER_OTLP_KEY[0..8]}...") if Config::MULTIPLAYER_OTLP_KEY != 'your-api-key-here'
60+
@logger.info(" API Key: #{Config::MULTIPLAYER_API_KEY[0..8]}...") if Config::MULTIPLAYER_API_KEY != 'your-api-key-here'
6161
rescue => e
6262
@logger.error("❌ Failed to initialize application: #{e.message}")
6363
@logger.error(e.backtrace.join("\n")) if Config::DEBUG
@@ -69,7 +69,7 @@ def start_session
6969
@logger.info("🎬 Starting debug session...")
7070

7171
@session_recorder.start(
72-
Multiplayer::SessionRecorder::Type::SessionType::PLAIN,
72+
Multiplayer::SessionRecorder::Type::SessionType::MANUAL,
7373
{
7474
name: Config::SESSION_NAME,
7575
resource_attributes: {

examples/cli/opentelemetry.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ def setup
1717

1818
# Create HTTP exporters
1919
@http_trace_exporter = Multiplayer::SessionRecorder::Exporters.create_http_trace_exporter(
20-
api_key: Config::MULTIPLAYER_OTLP_KEY,
20+
api_key: Config::MULTIPLAYER_API_KEY,
2121
endpoint: Config::MULTIPLAYER_TRACES_ENDPOINT
2222
)
2323

2424
@http_logs_exporter = Multiplayer::SessionRecorder::Exporters.create_http_logs_exporter(
25-
api_key: Config::MULTIPLAYER_OTLP_KEY,
25+
api_key: Config::MULTIPLAYER_API_KEY,
2626
endpoint: Config::MULTIPLAYER_LOGS_ENDPOINT
2727
)
2828

examples/http-server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
### Launch
99
```bash
10-
MULTIPLAYER_OTLP_KEY="your-key" ENVIRONMENT="staging" bundle exec ruby main.rb
10+
MULTIPLAYER_API_KEY="your-key" ENVIRONMENT="staging" bundle exec ruby main.rb
1111
```

lib/multiplayer_session_recorder/session_recorder.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def initialize
1616
@is_initialized = false
1717
@short_session_id = false
1818
@trace_id_generator = nil
19-
@session_type = Type::SessionType::PLAIN
19+
@session_type = Type::SessionType::MANUAL
2020
@session_state = 'STOPPED'
2121
@api_service = ApiService.new
2222
@resource_attributes = {}
@@ -141,7 +141,7 @@ def stop(session_data = {})
141141
raise RuntimeError, 'Session should be active or paused'
142142
end
143143

144-
unless @session_type == Type::SessionType::PLAIN
144+
unless @session_type == Type::SessionType::MANUAL
145145
raise RuntimeError, 'Invalid session type'
146146
end
147147

@@ -165,7 +165,7 @@ def cancel
165165

166166
if @session_type == Type::SessionType::CONTINUOUS
167167
@api_service.stop_continuous_session(@short_session_id)
168-
elsif @session_type == Type::SessionType::PLAIN
168+
elsif @session_type == Type::SessionType::MANUAL
169169
@api_service.cancel_session(@short_session_id)
170170
end
171171
ensure

lib/multiplayer_session_recorder/trace/id_generator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def initialize
1616
@generate_long_id = self.class.get_id_generator(16)
1717
@generate_short_id = self.class.get_id_generator(8)
1818
@session_short_id = ''
19-
@session_type = Type::SessionType::PLAIN
19+
@session_type = Type::SessionType::MANUAL
2020
end
2121

2222
def generate_trace_id
@@ -43,7 +43,7 @@ def generate_span_id
4343
@generate_short_id.call
4444
end
4545

46-
def set_session_id(session_short_id, session_type = Type::SessionType::PLAIN)
46+
def set_session_id(session_short_id, session_type = Type::SessionType::MANUAL)
4747
@session_short_id = session_short_id
4848
@session_type = session_type
4949
end

lib/multiplayer_session_recorder/type/session_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Multiplayer
44
module SessionRecorder
55
module Type
66
module SessionType
7-
PLAIN = 'plain'
7+
MANUAL = 'manual'
88
CONTINUOUS = 'continuous'
99
end
1010
end

0 commit comments

Comments
 (0)