Open Strum355 opened 4 years ago
I'm not able to reproduce this, which version of KGraphQL are you using?
I tried to create a unit test for this, but the test succeeds: https://gist.github.com/jeggy/ac6650a479d03d4e2122898cdb2f2ae4
Could you give a sample of what esRepo.getTraceByID(traceID)
does return?
Using 0.9.2
Trace(traceID=646851f15cb2dad1, spans=[Span(traceID=646851f15cb2dad1, spanID=32b1133c2e838c56, parentSpanID=646851f15cb2dad1, duration=1701547, startTime=1581974975400889, operationName=banana, serviceName=example1, logs=[], tags=[{type=string, value=sample text, key=_tracestep_stack}, {type=bool, value=true, key=_tracestep_main}, {type=string, value=proto, key=internal.span.format}]), Span(traceID=646851f15cb2dad1, spanID=7381e3787bb621db, parentSpanID=32b1133c2e838c56, duration=1000503, startTime=1581974975401257, operationName=start-req2, serviceName=example2, logs=[], tags=[{type=string, value=sample text, key=_tracestep_stack}, {type=bool, value=false, key=_tracestep_main}, {type=string, value=proto, key=internal.span.format}])])
Tried with 0.10.0 just now, same issue
I've released a new version 0.10.1, could you try with that version and you should get a different exception and paste that exception here?
com.apurebase.kgraphql.ExecutionException: Couldn't retrieve 'key' from class {type=string, value=proto, key=internal.span.format}}
at com.apurebase.kgraphql.schema.execution.ParallelRequestExecutor.createPropertyNode(ParallelRequestExecutor.kt:249)
at com.apurebase.kgraphql.schema.execution.ParallelRequestExecutor.handleProperty(ParallelRequestExecutor.kt:208)
at com.apurebase.kgraphql.schema.execution.ParallelRequestExecutor.createObjectNode(ParallelRequestExecutor.kt:185)
at com.apurebase.kgraphql.schema.execution.ParallelRequestExecutor.createNode(ParallelRequestExecutor.kt:149)
at com.apurebase.kgraphql.schema.execution.ParallelRequestExecutor$createNode$valuesMap$1.invokeSuspend(ParallelRequestExecutor.kt:131)
at com.apurebase.kgraphql.schema.execution.ParallelRequestExecutor$createNode$valuesMap$1.invoke(ParallelRequestExecutor.kt)
at com.apurebase.kgraphql.ExtensionsKt$toMapAsync$2$invokeSuspend$$inlined$map$lambda$1.invokeSuspend(Extensions.kt:46)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:561)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:727)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:667)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:655)
From this exception, Ive discovered that what i believed to be List\<Tag> was actually a HashMap. I wouldve thought that the cast would be checked at runtime, and that i wouldnt be able to assign whats actually a List\<HashMap> to List\<Tag> in a data class, but alas that seems to have been the case here :/ Not sure if this is intended behaviour for Kotlin or a bug Edited as \<xyz> was interpreted as HTML tags Edit 2: Type erasure is the conclusion ive come to, seeing as it was List\<HashMap> :smile:. Leaving the issue open in case you wish to make some internal changes for scenarios such as this
I'm not really following.
So you have your esRepo.getTraceByID(traceID)
function which returns a Trace
object. But somehow in your Trace.spans[0].tags
which is defined as ArrayList<Tag>?
, but holds a list( List<HashMap<?,?>>
) value?
is that HashMap then a HashMap<String, Any>
of something like this:
mapOf(
"_tracestep_stack" to "sample text",
"_tracestep_main" to false,
"internal.span.format" to "proto"
)
I would love to provide a good exception for something like this.
fun fromSearchHit(hit: SearchHit): Span {
val source = hit.sourceAsMap
...
val tags = (source.get("tags") as ArrayList<Tag>?)
}
hit.sourceAsMap
returns Map<String, Any>
. When i was casting the return of source.get("tags")
(of type Any
) to ArrayList<Tag>
, there is no runtime exception, even though the actual type is Arraylist<HashMap<Any, Any>>
(those Any may have been String, but the idea still holds). This is possibly due to Type Erasure, where the generic type is not checked. The JVM sees that the cast from Any to ArrayList is valid, but doesn't check the generic type as it does not exist at runtime
Output from
println
:Output from exception: