logging and alerting inside a gremlin step
I am trying to add a log statement inside the step but I am getting an error Server error: null (599)
ResponseError: Server error: null (599)
This is the error we get // Log the creation of a shell flight
.sideEffect(() => logger.info(
)
I only get this error when I log it in the sideEffect
This is the code we have:
await flightLegT
.fold()
.coalesce(
.unfold(),
.addV('flight')
.property(t.id, flightLegId)
.property('property1', .value1)
.property('property2', value2.)
.property('property3', value3)
.property('property4', value4)
.property('isShellFlight', true)
.as('shellFlight')
.sideEffect(
.V(originDateId).addE('vertex1').to(.select('shellFlight'))
)
.sideEffect(
.select('shellFlight').as('sf').addE('vertex2').from_(.select('sf'))
)
// Log the creation of a shell flight
.sideEffect(() => logger.info(
)
.as('flightLeg')
ResponseError: Server error: null (599)
This is the error we get // Log the creation of a shell flight
.sideEffect(() => logger.info(
Shell flight created for paxKey ${paxKey} with flightId ${flightLegID})))
I only get this error when I log it in the sideEffect
This is the code we have:
await flightLegT
.fold()
.coalesce(
.unfold(),
.addV('flight')
.property(t.id, flightLegId)
.property('property1', .value1)
.property('property2', value2.)
.property('property3', value3)
.property('property4', value4)
.property('isShellFlight', true)
.as('shellFlight')
.sideEffect(
.V(originDateId).addE('vertex1').to(.select('shellFlight'))
)
.sideEffect(
.select('shellFlight').as('sf').addE('vertex2').from_(.select('sf'))
)
// Log the creation of a shell flight
.sideEffect(() => logger.info(
Shell flight created for paxKey ${paxKey} with flightId ${flightLegID})))
.as('flightLeg')
Solution
Since you are getting a "Server error" I assume you are using Gremlin in a remote context. I'd further assume you are not sending a script to the server, but are using bytecode or are using a graph like Amazon Neptune. Those assumptions all point to the fact that you can't use a lambda that way in remote contexts.
The approach you are using to write your lambda is for embedded use cases only (i.e. where query is executed in the same JVM where it was created). If you want to send a lambda remotely you would need to have a server that supports them (e.g. Neptune does not, but Gremlin Server with Groovy ScriptEngine processing does) and then follow these instructions: https://tinkerpop.apache.org/docs/current/reference/#gremlin-java-lambda
The other thing to consider is that the lambda will be executed remotely so it might not know what "logger" is and the log message will appear on the server note the client.
Gremlin doesn't have a better way to really do what you are trying to do. I've often thought a
The approach you are using to write your lambda is for embedded use cases only (i.e. where query is executed in the same JVM where it was created). If you want to send a lambda remotely you would need to have a server that supports them (e.g. Neptune does not, but Gremlin Server with Groovy ScriptEngine processing does) and then follow these instructions: https://tinkerpop.apache.org/docs/current/reference/#gremlin-java-lambda
The other thing to consider is that the lambda will be executed remotely so it might not know what "logger" is and the log message will appear on the server note the client.
Gremlin doesn't have a better way to really do what you are trying to do. I've often thought a
debug() or print() step might be helpful in some way, but we've never gotten around to building that.