Databricks Connect
With Databricks Connect for Python and Scala, partners must set the userAgent as part of the connection parameters using the session builder.
Scala
import com.databricks.connect.DatabricksSession
import org.apache.spark.sql.SparkSession
object ScalaDbConnectTest {
def main(args: Array[String]): Unit = {
val spark: SparkSession =
DatabricksSession.builder
.userAgent("<isv-name_product-name>/<product-version>")
.getOrCreate()
println(s"Spark Version: ${spark.version}")
spark.sql("SELECT current_user(), current_timestamp()").show(false)
spark.stop()
}
}
Python
from databricks.connect import DatabricksSession
from databricks.sdk.core import Config
def main():
# Build SDK config from environment
config = Config()
user_agent = "<isv-name_product-name>/<product-version>"
print("User-Agent:", user_agent)
# Create Spark session with Databricks Connect
spark = (
DatabricksSession.builder
.sdkConfig(config)
.userAgent(user_agent)
.getOrCreate()
)
print(f"Spark version: {spark.version}")
# Verify current user/timestamp
verify_df = spark.sql("SELECT current_user() AS user, current_timestamp() AS ts")
verify_df.show(truncate=False)
# DataFrame test
df = spark.range(5)
print("Result:", df.collect())
print("Done.")
if __name__ == "__main__":
main()
What's next
- Configure libraries: Implement telemetry for Python and Scala libraries. See Libraries & UDFs.
- Configure Lakebase: Set up telemetry for PostgreSQL-compatible clients. See Lakebase Integrations.
- Review User-Agent format: Understand the required format and guidelines. See Telemetry & Attribution.