1
votes

I'm creating a Power BI custom connector in Visual Studio 2017 and I'd like for it to log during development.

I've followed the approach in the samples and specifically in the TripPin sample under diagnostics.

The diagnostics helper file Diagnostics.pqm is loaded in my .pq file:

Extension.LoadFunction = (name as text) =>
    let
        binary = Extension.Contents(name),
        asText = Text.FromBinary(binary)
    in
        Expression.Evaluate(asText, #shared);

// Diagnostics module contains multiple functions. We can take the ones we need.
Diagnostics = Extension.LoadFunction("Diagnostics.pqm");
Diagnostics.LogValue = if (EnableTraceOutput) then Diagnostics[LogValue] else (prefix, value) => value;

EnableTraceOutput is set to true and the Diagnostics.pqm file is set to 'Compile'. 'Show User Traces' is true in the project properties.

I've referenced the function:

shared GetSomeData = (test as logical, systemfolder as text) as table =>
    let
        #"SystemFolder" = Text.Trim(Text.Clean(systemfolder)),
        #"connstring" = "Provider=myprovider;Data Source=" & AddBs(#"SystemFolder") 
            & "seqco.dbf;Collating Sequence=machine;",
        _connstring = Diagnostics.LogValue("Conn String", #"connstring"),
        #"query" = "select stuff from table",
        data = OleDb.Query(#"connstring", #"query")
in
    data;

The function is executed and returns data but nothing gets logged as far as I can see.

1

1 Answers

1
votes

Typical, need to read the damn example properly, it should be invoked like this, using _connstring in OleDb.Query() will force it to evaluate:

shared GetSomeData = (test as logical, systemfolder as text) as table =>
    let
        #"SystemFolder" = Text.Trim(Text.Clean(systemfolder)),
        #"connstring" = "Provider=myprovider;Data Source=" & AddBs(#"SystemFolder") 
            & "seqco.dbf;Collating Sequence=machine;",
        _connstring = Diagnostics.LogValue("Conn String", #"connstring"),
        #"query" = "select stuff from table",
        data = OleDb.Query(_connstring, #"query")
in
    data;