Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two new flags to enable HTTP Server and clients logs #166

Open
wants to merge 2 commits into
base: release-candidate
Choose a base branch
from

Conversation

jvanecek
Copy link
Member

No description provided.

@codecov
Copy link

codecov bot commented Dec 17, 2022

Codecov Report

Merging #166 (fd3dbc2) into release-candidate (54a5b1f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@                 Coverage Diff                 @@
##           release-candidate     #166    +/-   ##
===================================================
  Coverage              99.83%   99.83%            
===================================================
  Files                    164      164            
  Lines                  12977    13147   +170     
===================================================
+ Hits                   12955    13125   +170     
  Misses                    22       22            
Impacted Files Coverage Δ
...PI-Skeleton-Tests/StargateApplicationTest.class.st 100.00% <100.00%> (ø)
...Stargate-API-Skeleton/StargateApplication.class.st 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@jvanecek jvanecek changed the title WIP: Enable to log all http requests Add two new flags to enable HTTP Server and clients logs Dec 17, 2022
@jvanecek jvanecek self-assigned this Dec 17, 2022
Copy link
Member

@gcotelli gcotelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jvanecek take a look at the comments.


ZnLogEvent announcer
when: ZnServerHandlerErrorEvent
do: [ :event | LaunchpadLogRecord emitError: event exception messageText ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can send directly a message to the event here, something like emitAsLogRecord, so we don't need to expose the internals of the event.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we can test more easily different combinations of event data

Extension { #name : #NeoJSONWriter }

{ #category : #'*Stargate-Model' }
NeoJSONWriter >> mapZincEvent [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs better tests, we need to be sure that every kind of object the event includes is properly mapped (like the abstractions we have in Hyperspace: WebLink, EntityTags, etc).

mapper
mapAccessor: #method;
mapProperty: #uri getter: [ :request | request uri printString ];
mapProperty: #body getter: [ :request | request contents ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to be careful here, I don't know if it's a good idea to just toss the contents of the request (a user-controlled thing) directly to the mapper. Probably we need to do something different for text and binary bodies and put an upper limit to the bytes to log.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. We need to think about the use cases and our broader context. I think that we can rely on a external component to do a detailed log about every request (too expensive at a smalltalk image level). Maybe we need just the URI and method.

Comment on lines +21 to +23
(response hasEntity and: [ response entity hasContentType ])
then: [ response contents asString copyNoMoreThanFirst: 4000 ]
otherwise: [ nil ] ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, we need to be extra careful with the kind of content we handle here. I think we need to make a distinction between textual and binary content.

{
ZnServerTransactionEvent.
ZnSimplifiedServerTransactionEvent.
ZnClientTransactionEvent } do: [ :event |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

event here can be eventType and this makes event available for the inner temp


self for: ZnHeaders customDo: [ :mapping |
mapping writer: [ :jsonWriter :headers |
jsonWriter writeMap: headers ] ].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some headers will have sensitive data (like the Authorization ones), so we need to mask these ones to not expose sensitive information in the logs.

Comment on lines +235 to +245
| eventJson |
eventJson := NeoJSONObject fromString:
(String streamContents: [ :stream |
(NeoJSONWriter on: stream)
mapZincEvent;
nextPut: aZincEvent ]).
aLogRecordJson
at: #summary put: eventJson summary;
at: #request put: eventJson request;
at: #response put: eventJson response
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to consider the possibility of something that can be mapped here, and producing an error log record in this case, but not killing the app because some log records cannot be produced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants