Skip to content

Passing trace id from JS client to a database comment#2587

Merged
cprieto merged 4 commits intomainfrom
tmp-trace
Jan 14, 2022
Merged

Passing trace id from JS client to a database comment#2587
cprieto merged 4 commits intomainfrom
tmp-trace

Conversation

@cprieto
Copy link
Copy Markdown
Contributor

@cprieto cprieto commented Jan 14, 2022

Current tracing implementation in the Node API conflicts with the OpenTelemetry collector layer, this makes really difficult to collect tracing information for technical reasons (explanation is a little long, ask me if you want more details).

This is (hopefully) a temporary solution for prisma/prisma#10004 and is required for prisma/prisma#10310 until we have more time to reconstruct the logging support for the QE in the Node API, right now we just pass whatever we get from the client to the database as a database comment, for example:

const path = require('path')
const fs = require('fs')

const { QueryEngine } = require(path.join(__dirname, 'query-engine.node'))

let query = fs.readFileSync('test.json', 'utf-8')

async function main() {
    let q = new QueryEngine({
        datamodel: fs.readFileSync(path.join(__dirname, 'test.prisma'), 'utf-8'),
        logLevel: 'info',
        telemetry: {
            enabled: false,
        },
        configDir: process.cwd(),
    }, err => console.log(err))

    let traceparent = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
    console.log(`original trace: ${traceparent}`)
    await q.connect({ enableRawQueries: true })
    let res = await q.query(query, `{"traceparent": "${traceparent}"}`)

    await new Promise(_ => setTimeout(_, 500))
    console.log(res)
}

main().then(console.log).catch(console.error)

would generate a SQL command like this one:

SELECT `prisma`.`User`.`id`, `prisma`.`User`.`name` FROM `prisma`.`User` WHERE `prisma`.`User`.`id` = 1 
/* traceparent=00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01 */

Passing trace id is required to handle tracing information. This is a temporary solution and it will be resolved when logging is improved.
This will complete (from the Rust side) #10004
@cprieto cprieto requested a review from dpetrick January 14, 2022 14:50
 - Make cargo check happy
 - Make @dom happy
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.

3 participants