-
Notifications
You must be signed in to change notification settings - Fork 22
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
Pass contextual information to the worker #99
Comments
Don't you control the application's dependencies? I think it would be simpler to set a minimum install version of the dependency in your application such that it supports the features you need. |
That'd be handy. Would you like to send a PR? You can include it in Line 52 in 7135302
|
Yes but It won't matter that much if
Sure! So I was thinking something like: workerData = {
'$context': {
threadStreamVersion: version
},
...workerData
} I'm using a special prefix to avoid conflicts. I don't have any preference about the prefix character though. |
Which is all handled by the semver ranges specified in those direct dependencies. 🤷♂️ |
I don't think we should add an explicit dependency on So, one way would be to explicitly add a dependency on |
I do not understand the setup. Whatever application is using |
Pino is using Lines 152 to 175 in 7135302
This "protocol" changed in version 2.1.0 and now it allows messages with the code This is not a major version because the protocol is backward compatible but if a transport sends a message with the code
Does it make sense? Are you suggesting that user applications should manage pino and thread-stream versions independently while making sure that pino version X is compatible with thread-stream version Y? |
My concern is adding more features to maintain. Are you saying you want to modify the |
Yes, but it's not really a new feature, it's an existing feature that does not work when the transport is executed as a worker (through With the following code, you can listen to the // transport
outputStream.emit('socketError', error)
if (parentPort) {
parentPort.postMessage({ code: 'EVENT', name: 'socketError', args: [error] })
}
// application
const socketStream = pino.transport({
target: "pino-socket",
options: {
address: tcpAddress,
port: tcpPort,
mode: "tcp",
reconnect: true,
}
})
// works even if socketStream is a ThreadStream
socketStream.on('socketError', (error) => {
// do something!
}) Ideally, it should be transparent but as far as I know it's not possible to listen to events from another thread? |
I was about to publish events using
postMessage({ code: 'EVENT', name: 'eventName', args: [] })
in pino-socket but I don't know how to make sure that the event code is "supported" bythread-stream
. In other words, it's only safe to post anEVENT
message if we are usingthread-stream
> 2.1.x. If we are using older versions it will destroy the stream:thread-stream/index.js
Line 167 in 7a395f7
Anyway, I was wondering if it would make sense to pass contextual information, such as the version (or a list of capabilities? or a "communication protocol" version) to the worker?
It would allow the transport/worker to communicate with the thread stream "safely" knowing which messages can be sent.
I'm also open to ideas on how to solve this issue.
Follow-up: #97
The text was updated successfully, but these errors were encountered: