You need to enable JavaScript to run this app.
导航
Java
最近更新时间:2023.12.19 19:53:38首次发布时间:2023.05.29 11:14:02
一、简介

火山引擎DataSail提供埋点数据上报Java SDK,用户在开通DataSail服务之后,可以通过SDK将数据上报到火山云。

二、前置准备

服务开通

请确保您已开通了您需要访问的服务。您可前往火山引擎控制台开通全域数据集成服务,详见服务开通

获取安全凭证

Access Key(访问密钥)是访问火山引擎服务的安全凭证,包含Access Key ID(简称为AK)和Secret Access Key(简称为SK)两部分。您可登录火山引擎控制台,前往访问控制访问密钥 中创建及管理您的Access Key。更多信息可参考访问密钥帮助文档

产品接入

  1. 申请应用

路径:应用管理-新建应用

  1. 申请Topic

路径:数据采集-topic管理-新建Topic

  1. 申请数据采集

路径:数据采集-采集管理-新建采集任务

三、上报示例

环境

  • Java 8

  • Maven (推荐使用3.1.1及以上版本)

  • 运行环境 (Linux, Mac OS X)

参数

参数名类型配置项含义示例备注
ConfigCallerstring代表业务名称datasail.dataset.test

AccessKey

string

火山云 Access Key

AKLTZWU*****

SecretKey

string

火山云 Secret Key

TW1KaVl******

Domainstring数据上报域名datasail01-cn-beijing.volceapplog.com
TaskKeystring采集任务IDhkktppvwtuv0xy000获取路径:数据采集->采集管理->采集任务 ID 🔗
Aidint应用APP ID500000获取路径:应用管理->APP ID 🔗
IsDebudboolean是否开启埋点验证false开启埋点验证开关,数据会双发到验证链路
Regionstring数据上报区域cn-beijing

代码示例

  1. 将jar包导入maven本地仓库
    datasail-collector-java-cloud.jar
    35.34KB

    datasail-schema.jar
    336.65KB
mvn install:install-file -Dfile=datasail-collector-java-cloud.jar -DgroupId=com.volcengine -DartifactId=datasail-collector-java-cloud -Dversion=1.0.0-SNAPSHOT -Dpackaging=jar
mvn install:install-file -Dfile=datasail-schema.jar -DgroupId=com.volcengine -DartifactId=datasail-schema -Dversion=1.0.0-SNAPSHOT -Dpackaging=jar
  1. 添加以下pom依赖

    <properties>
        <datasail.version>1.0.0-SNAPSHOT</datasail.version>
        <volcengine.version>1.0.49</volcengine.version>
        <slf4j.version>1.7.25</slf4j.version>
        <httpclient.version>4.5.8</httpclient.version>
        <protobuf.format.version>1.4</protobuf.format.version>
        <schema.version>1.0.0-SNAPSHOT</schema.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>com.volcengine</groupId>
            <artifactId>datasail-collector-java-cloud</artifactId>
            <version>${datasail.version}</version>
        </dependency>
        <dependency>
            <groupId>com.volcengine</groupId>
            <artifactId>volc-sdk-java</artifactId>
            <version>${volcengine.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${httpclient.version}</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.protobuf-java-format</groupId>
            <artifactId>protobuf-java-format</artifactId>
            <version>${protobuf.format.version}</version>
        </dependency>
        <dependency>
            <groupId>com.volcengine</groupId>
            <artifactId>datasail-schema</artifactId>
            <version>${schema.version}</version>
        </dependency>
    </dependencies>
    
  2. 数据上报

import com.bytedance.datasail.collector.Collector;
import com.bytedance.datasail.collector.CollectorManager;
import com.bytedance.datasail.model.Config;
import com.bytedance.protobuf.mario.EventProto;

public static void main(String[] args) {

    String caller = "your caller"
    String ak = "your ak";
    String sk = "your sk";
    String domain = "http://xxx";
    String taskKey = "xxx";
    String region = "cn-beijing";
    int aid = 0;   // your app id
    Boolean isDebud = true;

    Config config = new Config.Builder()
            .accessKey(ak)
            .caller(caller)
            .secretKey(sk)
            .taskKey(taskKey)
            .region(region)
            .isDebug(isDebud).build();

    Collector collector = CollectorManager.getInstance(domain, config);

    EventProto.User.Builder user = EventProto.User.newBuilder()
            .setUserUniqueId("test-event-user");
    EventProto.Header.Builder header = EventProto.Header.newBuilder()
            .setAppId(aid);
    EventProto.Event.Builder event = EventProto.Event.newBuilder()
            .setEvent("test-event")
            .setTime((int) (System.currentTimeMillis() / 1000))
            .setParams("{}");
    try {
        collector.collectEvent(user, header, event);
    } catch (Exception e) {
        System.out.println(e);
    }
}

安全声明

Java开源组件声明.txt
21.04KB