GraphQL Severity Filter
Hello! Does anyone know how to filter for
severity:error
on GraphQL? (its the @level:error
in the railway dashboard, or any other severity)
I've tried a few combinations like filter: "@severity:error"
or filter: "@level:error"
none of which seems to work.67 Replies
Project ID:
N/A
N/A
I'm sorry this has slipped through the cracks, did you still need help with this?
and either way, I would love to hear your usecase, it sounds like you are trying to subscribe to the logs?
Hi yes, thanks for the reply, no worries about the slippage.
Basically I'm trying to create a graphql subscription service that looks for
@level:error
from the deploymentLogs. (specifically the one in severity
)
From playing around in railways graphql playground https://railway.app/graphiql I can't seem to filter for any severity level. Heres the code
This is also checked against Observerability’s network tab in my railway’s dashboard which confirms that the syntax im using is correct
just checked, the syntax is indeed correct.
are you trying to make your own notification system for errors in your logs? or are you trying to pipe your logs to a 3rd party logging service?
Im trying to make my own notification system to link with discord / telegram
like this?
Something like that i suppose
This brings me to my next problem 😂 , i've got the bots to trigger now, but i can't seem to create a subscription onto railway's graphql at all through code
do you know what templates are?
no sorry i dont
What are they?
templates are ready to use projects that you can easily deploy on railway
this bot is a template my friend and i worked on, would you want to give it a try? maybe it covers your usecase
Sure thing, would love to give it a try 🙏
okay you will need 3 things
- a railway api token
- your service id of the service you want to monitor
- your discord webhook url
open a notepad and ill walk you though how to get the first two
Oh um hmm im sry maybe i actually can't provide these data since this isn't my personal project 🥹, ill get back to u on this once i get an answer
no no i dont want you to give them to me
you would need to put them in a note so you can use them with the template, you are the only person who will ever have access to anything i just mentioned
Oh ok sure thing
sounds good
perhaps i should go into more details about the template in question
Hahah that would be nice
the template is called locomotive and it is a service you deploy into an existing project and it will connect to railway's api and forward your logs of the desired service to either discord (as ive shown) or any generic webhook url (for services like axiom or betterstack)
the service subscribes to the logs the same way you are trying to do, but handles everything for you like filtering and auto re-subscriptions.
you simply deploy it into your project and provide it with the 3 things i mentioned above (and a level you want to filter) and it will send you discord embeds for your logs.
Yep that sounds pretty close to wat im trying to do tbh
sample screenshot of deploying the template and how you fill out the needed info
youll just need to gather the needed info in a notepad so that you have all the info in a single place when you go to deploy the template, just makes it easier
This looks very well made
https://github.com/FerretCode/locomotive/tree/main
this repo right?
GitHub
GitHub - FerretCode/locomotive
Contribute to FerretCode/locomotive development by creating an account on GitHub.
yep
btw i saw this in the observability network tab too, whats the difference
environmentLogs
and deploymentLogs
?
seems like the railway's playground doesn't have access to the environmentLogs
?good question,
environmentLogs
would be a subscription that returns the logs (both build and deploy) for all the services within a given environment.
deploymentLogs
would return only the logs for the given deployment.
correct, the playground uses the public api endpoint and that subscription is not available on the public api endpoint yetmaybe theres a bug in the
deploymentLogs
for filtering then?im not sure tbh, but i do know that the dashboard does not call
deploymentLogs
instead it calls environmentLogs
with a deploymentId filter
but if youd like to try locomotive, let me know and ill help you find the info it needs to work, its simple!Yessir sure thing thanks alot for the help. I will check it out at work tmr 🙏
I see u have a cron job repo to hahha
i've actually resorted to making my service a cron job for tday lol just so the log notifies
yeah its sometimes slightly more useful than railway's cron job in some aspects since it can restart long running services like web servers where as railways cron job expects the thing being run to run and then exit, otherwise if its still running the jobs are skipped
I see, seems like a useful repo for me too 😂
both locomotive and my cron service come as templates, you wouldnt need to use the repo directly
this one right? for the locomotive
yep, but make sure its deployed into a pre-existing project
did you want to know where to find the info it needs now?
Oh yes please
i assume you know where to get your discord webhook?
yep
okay go ahead and put that in a note
ok got it
an account token and a service id have the same format (UUIDv4), make sure to denote what is what when you copy them down.
- generate an account token here - https://railway.app/account/tokens and copy that token down.
- open your desiered service and copy down just the serviceId found in the url
/service/<service id>
for context, the account token is very sensitive, but the project, environment, service ids, deployment ids are not in the least bit sensitiveOk found both
hence why i had no problem showing you them here
ah i see, thts good to know
okay go into the same project that your desired service is in and deploy the locomotive template
RAILWAY_API_KEY
-> self explanatory 🤣
TRAIN
-> your service id of the service you want to monitor
DISCORD_WEBHOOK_URL
-> also self explanatory
INGEST_URL
-> not needed as you are only doing discord right now, but it would be used for axiom, betterstack, etc
ADDITIONAL_HEADERS
-> also not needed, but would be used to authenticate with axiom, betterstack, etc when using INGEST_URL
expand the pre configured variables section and you can fill out the LOGS_FILTER_DISCORD
to error
quick question for you, have you heard of axiom or betterstack?tbh no for both
they are both logging platforms where you can sends logs to and then set up observability on, for stuff like error levels
arguably better suited for this task than discord haha
Oh btw i jst digged through discord, found one of ur chats about
this actually solved my problem allowing my code to run the query
yeah i figured, but i thought locomotive would be a ready to use solution for you
actually i was searching for environmentLog
btu found that
hahaha
i dont know how closely you looked into locomotive's code but it uses the environment logs
When i tried to use environmentLog (without passing any variable 😂 ) i get this error though
Error fetching logs: [
{
message: 'Cannot query field "environmentLogs" on type "Subscription". Did you mean "deploymentLogs"?',
locations: [ [Object] ]
}
]
yeah you need to use the internal api endpoint
https://github.com/FerretCode/locomotive/blob/main/main.go#L41C25-L41C69
where you able to give locomotive a try?
Will try this out fully tmr with the team and let u know ✌️
btw where can i get the environmentId from railway?
as long as you deploy locomotive into the same project as the service you want to get logs from, it will be autofilled for you
tysm for the help tho, do u want any specific feedback from using ur template?
its my friends template, ive just worked on it a bunch, but for feedback, id like to know if it doesnt meet your needs, and if so, what does it need to do to meet your needs
Ok sure thing, will get u the feedback when i work on it
thanks!
Hey got a chance to test out the template today, i think overall it works nicely right out the box, its something id definitely use on my personal project
In the end though i decided to use my own code for querying and hooking up to discord webhook as we plan to use this repo for services othen then railway log monitoring
e.g. cron job automated testing services
okay makes sense, I'm glad it still did work though!
just be sure your code can handle the resubscription with log resuming otherwise you could lose a few log lines every 10 or so minutes
Hahah thats actually on my ticket for tmr, but now tht uve mentioned it, do u mind pointing me in teh right direction
rn the log continuously spits out empty array which i ignore and just dont send them as message
the best help I could give you would be to tell you to look at locomotive's subscription code
Ok sure thing ill dig into that