设置 Java 和 Scala 环境以使用遥测类

You can build and package handler code that uses the com.snowflake.telemetry.Telemetry class, then reference the handler on a stage. The Telemetry library is available through Maven and through an archive file that you can download from the Drivers and Libraries page (https://developers.snowflake.com/drivers-and-libraries/) in the Snowflake Developer site.

如果您使用 Maven 开发 Java 或 Scala 中的函数或过程处理程序,则可以构建包含代码的 JAR 文件:

  1. In the pom.xml file for your project, add a dependency on the com.snowflake:telemetry package:

    <dependency>
      <groupId>com.snowflake</groupId>
      <artifactId>telemetry</artifactId>
      <version>0.01</version>
    </dependency>
  2. Exclude the telemetry package from the JAR file that you build because it is already included in Snowflake.

    1. In the directory for your project, create a subdirectory named assembly/.

    2. 在该目录中,创建一个程序集描述符文件,该文件指定要在 JAR 文件中包含依赖关系。

      For an example, see jar-with-dependencies (https://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies).

    3. In the assembly descriptor, add a <dependencySet> element that excludes the Snowpark library from your JAR file. For example:

      <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
        <id>jar-with-dependencies</id>
        <formats>
      <format>jar</format>
        </formats>
        <includeBaseDirectory>false</includeBaseDirectory>
        <dependencySets>
          <dependencySet>
      <outputDirectory>/</outputDirectory>
      <useProjectArtifact>true</useProjectArtifact>
      <unpack>true</unpack>
      <scope>runtime</scope>
      <excludes>
        <exclude>com.snowflake:telemetry</exclude>
      </excludes>
          </dependencySet>
        </dependencySets>
      </assembly>

      For information about the elements in an assembly descriptor, see Assembly Descriptor Format (https://maven.apache.org/plugins/maven-assembly-plugin/assembly.html).

  3. In your pom.xml file, under the <project> » <build> » <plugins>, add a <plugin> element for the Maven Assembly Plugin.

    In addition, under <configuration> » <descriptors>, add a <descriptor> that points to the assembly descriptor file that you created in the previous steps.

例如:

<project>
  [...]
  <build>
 [...]
 <plugins>
   <plugin>
     <artifactId>maven-assembly-plugin</artifactId>
     <version>3.3.0</version>
     <configuration>
       <descriptors>
         <descriptor>src/assembly/jar-with-dependencies.xml</descriptor>
       </descriptors>
     </configuration>
     [...]
   </plugin>
   [...]
 </plugins>
 [...]
  </build>
  [...]
</project>