Skip to content

Commit a7acf47

Browse files
committed
fixed missing puma details for docs, use start event
1 parent a133118 commit a7acf47

File tree

15 files changed

+103
-143
lines changed

15 files changed

+103
-143
lines changed

lib/log_struct/enums/event.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,8 @@ class Event < T::Enum
4040
Restore = new(:restore)
4141

4242
# Server lifecycle (e.g., Puma)
43-
Boot = new(:boot)
44-
Started = new(:started)
45-
Listening = new(:listening)
43+
# Start already defined above
4644
Shutdown = new(:shutdown)
47-
Goodbye = new(:goodbye)
48-
Exiting = new(:exiting)
4945

5046
# Security events
5147
IPSpoof = new(:ip_spoof)

lib/log_struct/integrations/puma.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def emit_boot_if_needed!
299299
sig { void }
300300
def emit_started!
301301
si = T.cast(STATE[:start_info], T::Hash[Symbol, T.untyped])
302-
log = Log::Puma::Started.new(
302+
log = Log::Puma::Start.new(
303303
mode: T.cast(si[:mode], T.nilable(String)),
304304
puma_version: T.cast(si[:puma_version], T.nilable(String)),
305305
puma_codename: T.cast(si[:puma_codename], T.nilable(String)),

lib/log_struct/log/puma.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
# Schemas dir: schemas/log_sources/
77
# Template: tools/codegen/templates/sorbet/source_parent.rb.erb
88

9-
require_relative "puma/boot"
10-
require_relative "puma/started"
9+
require_relative "puma/start"
1110
require_relative "puma/shutdown"

lib/log_struct/log/puma/boot.rb

Lines changed: 0 additions & 80 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
module LogStruct
2121
module Log
2222
class Puma
23-
class Started < T::Struct
23+
class Start < T::Struct
2424
# typed: strict
2525
# frozen_string_literal: true
2626

@@ -30,7 +30,7 @@ class Started < T::Struct
3030

3131
# Shared/common fields
3232
const :source, Source::Puma, default: Source::Puma
33-
const :event, Event, default: Event::Started
33+
const :event, Event, default: Event::Start
3434
const :timestamp, Time, factory: -> { Time.now }
3535
const :level, Level, default: Level::Info
3636

lib/log_struct/railtie.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Railtie < ::Rails::Railtie
7373
break
7474
end
7575
end
76-
started = LogStruct::Log::Puma::Started.new(
76+
started = LogStruct::Log::Puma::Start.new(
7777
mode: "single",
7878
environment: (defined?(::Rails) && ::Rails.respond_to?(:env)) ? ::Rails.env : nil,
7979
process_id: Process.pid,

rails_test_app/templates/test/integration/puma_integration_test.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,22 @@ def test_rails_server_emits_structured_puma_logs_and_on_exit
7474
end
7575
puma_logs = after_json.select { |h| h["src"] == "puma" }
7676

77-
# Expect exactly 2 structured logs: started, shutdown
77+
# Expect exactly 2 structured logs: start, shutdown
7878
assert_equal 2, puma_logs.length, "Expected exactly 2 Puma logs. Output: #{output}\nSTDERR: #{stderr.read}"
7979

8080
events = puma_logs.map { |h| h["evt"] }
8181

82-
assert_equal ["started", "shutdown"], events, "Expected Puma events in order: started, shutdown"
82+
assert_equal ["start", "shutdown"], events, "Expected Puma events in order: start, shutdown"
8383

84-
started = puma_logs[0]
84+
start = puma_logs[0]
8585

86-
assert_equal "puma", started["src"]
87-
assert_equal "info", started["lvl"]
88-
assert_equal "single", started["mode"]
89-
assert_equal "test", started["environment"]
90-
assert_kind_of Integer, started["pid"]
91-
assert_kind_of Array, started["listening_addresses"]
92-
assert started["listening_addresses"].any? { |a| a.include?(":#{port}") }, "Expected listening address to include :#{port}"
86+
assert_equal "puma", start["src"]
87+
assert_equal "info", start["lvl"]
88+
assert_equal "single", start["mode"]
89+
assert_equal "test", start["environment"]
90+
assert_kind_of Integer, start["pid"]
91+
assert_kind_of Array, start["listening_addresses"]
92+
assert start["listening_addresses"].any? { |a| a.include?(":#{port}") }, "Expected listening address to include :#{port}"
9393

9494
shutdown = puma_logs[1]
9595

schemas/log_sources/puma.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ snake_case: puma
55
additional_data: true
66

77
events:
8-
Boot:
9-
fields:
10-
ProcessId: Integer
11-
12-
Started:
8+
Start:
139
default_required: false
1410
fields:
1511
Mode: String

site/components/integration-examples.tsx

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import React from 'react';
3+
import React, { useId } from 'react';
44
import { useFiltering } from '@/components/filtering-context';
55
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
66
import { CodeBlock } from '@/components/code-block';
@@ -21,9 +21,11 @@ export function IntegrationExamples({
2121
}) {
2222
const { filtering, setFiltering } = useFiltering();
2323
const gen = new LogGenerator(12345, filtering);
24+
const baseFilteringId = useId();
2425

2526
if (events.length <= 1) {
2627
const only = events[0];
28+
const inputId = `${baseFilteringId}-filter`;
2729
return (
2830
<div className="relative">
2931
<CodeBlock language="json">
@@ -35,11 +37,14 @@ export function IntegrationExamples({
3537
)}
3638
</CodeBlock>
3739
<div className="absolute bottom-2 right-3 text-xs text-neutral-500 dark:text-neutral-400 flex items-center gap-2 bg-white/60 dark:bg-neutral-900/60 px-2 py-1 rounded">
38-
<label className="cursor-pointer select-none">Apply filtering</label>
40+
<label className="cursor-pointer select-none" htmlFor={inputId}>
41+
Apply filtering
42+
</label>
3943
<input
4044
aria-label="Apply filtering"
4145
type="checkbox"
4246
className="cursor-pointer"
47+
id={inputId}
4348
checked={filtering}
4449
onChange={(e) => setFiltering(e.target.checked)}
4550
/>
@@ -62,32 +67,43 @@ export function IntegrationExamples({
6267
</TabsTrigger>
6368
))}
6469
</TabsList>
65-
{events.map((evt) => (
66-
<TabsContent key={String(evt)} value={String(evt)} className="mt-0.5">
67-
<div className="relative">
68-
<CodeBlock language="json">
69-
{formatLog(
70-
gen.generateLogWithOptions(logType, {
71-
preferredEvent: evt,
72-
filtering,
73-
}),
74-
)}
75-
</CodeBlock>
76-
<div className="absolute bottom-2 right-3 text-xs text-neutral-500 dark:text-neutral-400 flex items-center gap-2 bg-white/60 dark:bg-neutral-900/60 px-2 py-1 rounded">
77-
<label className="cursor-pointer select-none">
78-
Apply filtering
79-
</label>
80-
<input
81-
aria-label="Apply filtering"
82-
type="checkbox"
83-
className="cursor-pointer"
84-
checked={filtering}
85-
onChange={(e) => setFiltering(e.target.checked)}
86-
/>
70+
{events.map((evt) => {
71+
const inputId = `${baseFilteringId}-${String(evt)}`;
72+
return (
73+
<TabsContent
74+
key={String(evt)}
75+
value={String(evt)}
76+
className="mt-0.5"
77+
>
78+
<div className="relative">
79+
<CodeBlock language="json">
80+
{formatLog(
81+
gen.generateLogWithOptions(logType, {
82+
preferredEvent: evt,
83+
filtering,
84+
}),
85+
)}
86+
</CodeBlock>
87+
<div className="absolute bottom-2 right-3 text-xs text-neutral-500 dark:text-neutral-400 flex items-center gap-2 bg-white/60 dark:bg-neutral-900/60 px-2 py-1 rounded">
88+
<label
89+
className="cursor-pointer select-none"
90+
htmlFor={inputId}
91+
>
92+
Apply filtering
93+
</label>
94+
<input
95+
aria-label="Apply filtering"
96+
type="checkbox"
97+
className="cursor-pointer"
98+
id={inputId}
99+
checked={filtering}
100+
onChange={(e) => setFiltering(e.target.checked)}
101+
/>
102+
</div>
87103
</div>
88-
</div>
89-
</TabsContent>
90-
))}
104+
</TabsContent>
105+
);
106+
})}
91107
</Tabs>
92108
</div>
93109
);

site/lib/__tests__/log-structure-descriptions.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ describe('Log Structure Descriptions', () => {
4040
it('getLogStructureDescription throws an error for unknown structures', () => {
4141
// Test with an unknown structure
4242
expect(() => getLogStructureDescription('NonExistentStructure')).toThrow(
43-
'No description found for log structure: NonExistentStructure',
43+
'No description found for log structure: NonExistentStructure. ' +
44+
'Add it to lib/log-structure-descriptions.ts',
4445
);
4546
});
4647
});

0 commit comments

Comments
 (0)